Skip to content

Try using unordered_map hash in DacInstanceManager#123737

Draft
hoyosjs wants to merge 2 commits intodotnet:mainfrom
hoyosjs:juhoyosa/dacinstance_hash
Draft

Try using unordered_map hash in DacInstanceManager#123737
hoyosjs wants to merge 2 commits intodotnet:mainfrom
hoyosjs:juhoyosa/dacinstance_hash

Conversation

@hoyosjs
Copy link
Member

@hoyosjs hoyosjs commented Jan 28, 2026

No description provided.

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fix gcc error, line 1549:

-    DAC_INSTANCE *(&target) = m_hash[inst->addr];
+.   DAC_INSTANCE*& target = m_hash[inst->addr];

Copilot AI review requested due to automatic review settings February 27, 2026 04:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR switches DacInstanceManager’s instance lookup structure to the std::unordered_map-based implementation by default, and updates the custom hashing hook to avoid reliance on non-portable hash_compare.

Changes:

  • Disable the hand-rolled DAC hashtable by default (DAC_HASHTABLE) so the unordered_map path is used.
  • Replace std::hash_compare-based hashing with a portable unary hash functor for std::unordered_map.
  • Minor cleanup in daccess.cpp (reference declaration simplification; remove unused local).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/coreclr/debug/daccess/dacimpl.h Switches default to unordered_map and replaces the hasher implementation with a portable functor.
src/coreclr/debug/daccess/daccess.cpp Small cleanups in the unordered_map codepath (reference syntax; remove unused variable).

};
typedef std::unordered_map<TADDR, DAC_INSTANCE*, DacHashCompare > DacInstanceHash;
// typedef std::unordered_map<TADDR, DAC_INSTANCE*, DacHashCompare > DacInstanceHash;
// Start the experiment without bringing in hash_compare which was moved to stdex and isn't portable.
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says stdex, but the MSVC extension namespace for hash_compare is stdext. This typo makes the rationale harder to understand; please correct the namespace in the comment.

Suggested change
// Start the experiment without bringing in hash_compare which was moved to stdex and isn't portable.
// Start the experiment without bringing in hash_compare which was moved to stdext and isn't portable.

Copilot uses AI. Check for mistakes.

};
typedef std::unordered_map<TADDR, DAC_INSTANCE*, DacHashCompare > DacInstanceHash;
// typedef std::unordered_map<TADDR, DAC_INSTANCE*, DacHashCompare > DacInstanceHash;
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the commented-out typedef line. Keeping dead/commented-out code in the header adds noise and makes it unclear which declaration is intended to be authoritative.

Suggested change
// typedef std::unordered_map<TADDR, DAC_INSTANCE*, DacHashCompare > DacInstanceHash;

Copilot uses AI. Check for mistakes.
Comment on lines +735 to 736
struct DacHashCompare
{
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DacHashCompare is used purely as the hash functor for std::unordered_map (it doesn't define a comparison). Consider renaming it to something like DacInstanceHash/DacHasher to better reflect its role.

Copilot uses AI. Check for mistakes.
Comment on lines 19 to +22
// Setting DAC_HASHTABLE tells the DAC to use the hand rolled hashtable for
// storing code:DAC_INSTANCE . Otherwise, the DAC uses the STL unordered_map to.

#define DAC_HASHTABLE
// #define DAC_HASHTABLE
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting out #define DAC_HASHTABLE changes the default behavior for all builds. If the intent is to make this a configurable experiment, consider moving the default selection to the build system (e.g., a feature flag/define) rather than leaving a commented-out macro in the header.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Significant decrease in performance of mini dump creation between targeting .NET Framework 4.6.1 and .NET 8

3 participants