-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Faster optimized frozen dictionary creation (2/n) #87630
Conversation
This reverts commit 204e175.
…oids a closure, index boundary checks and helps with inlining (7% gain) in case of hash set of integers it avoids renting and copying all integers to just have a copy of them
…ont (2-4% gain) * in CreateLengthBucketsFrozenDictionaryIfAppropriate iterate over array rather than dictionary * in OrdinalStringFrozenDictionary ctor avoid creating a copy of all entires (we already have a copy of keys)
…ength is the replacement)
Tagging subscribers to this area: @dotnet/area-system-collections Issue Details
LaunchCount=9 MemoryRandomization=True
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love the duplication, but I don't have a better suggestion for avoiding the delegate overhead. Nice bump. Thanks.
_hashTable = FrozenHashTable.Create( | ||
entries.Length, | ||
index => entries[index] is T t ? Comparer.GetHashCode(t) : 0, | ||
hashCodes, | ||
(destIndex, srcIndex) => _items[destIndex] = entries[srcIndex], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not entirely familiar with the implementation, but curious why we're doing delayed initialization for the _items
array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not delayed, it's happening during the call to Create, which is helping to put the values in the right spot.
FrozenHashTable.Create
provide the hashcodes, it eliminates a closure and boundary checks and one method call (7% gain)CreateLengthBucketsFrozenDictionaryIfAppropriate
iterate over array rather than dictionaryOrdinalStringFrozenDictionary
ctor avoid creating a copy of all entries (we already have a copy of keys)