-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Implement SegmentedDictionary<TKey, TValue> #50156
Conversation
These files are based on dotnet/runtime@cf258a14 (v5.0.0-rtm.20519.4).
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The APIs providing the scenario are not public, and not easily ported.
0055246
to
7db5534
Compare
@@ -13,13 +13,57 @@ internal static class SegmentedArray | |||
/// <seealso cref="Array.Clear(Array, int, int)"/> | |||
internal static void Clear<T>(SegmentedArray<T> buckets, int index, int length) | |||
{ | |||
throw new NotImplementedException(); | |||
if (index < 0 || length < 0 || (uint)(index + length) > (uint)buckets.Length) | |||
ThrowHelper.ThrowArgumentOutOfRangeException(); |
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.
Consider breaking this up and including the argument that was out of range.
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.
This is the same check used for Array.Clear
:
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.
With that said, this class is weird - the instinct is to keep all the original coding approach from Array
but it's both ugly and difficult to port directly. So I could really go either way on it.
Done review pass (commit 15) |
This code normally runs in a 64-bit process, so favor the faster implementation for that case.
4304898
to
aa2ec01
Compare
@jaredpar Can you review this? |
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.
When copying code from other repos we should link to that code so bug and security fixes can be ported.
c3b3d7a
to
7ff5c6f
Compare
This collection is derived from
Dictionary<TKey, TValue>
(dotnet/runtime@cb5f173b, which is .NET 5.0.2), with the backing arrays replaced bySegmentedArray<T>
to avoid all Large Object Heap allocations. In most cases, the performance of this collection is indistinguishable fromDictionary<TKey, TValue>
, with the exception of not using the Large Object Heap.Aside from the changes to segment the storage arrays, the following changes are made relative to the original implementation:
SegmentedDictionary<TKey, TValue>
does not support binary serializationSegmentedDictionary<TKey, TValue>
always uses default string comparers by default, and does not attempt to force the use of non-randomized comparers for performance in low-collision scenariosSegmentedDictionary<TKey, TValue>
always uses HashHelpers.FastMod, which optimizes AnyCPU performance for 64-bit runtimes💡 If necessary, updates from dotnet/runtime can be incorporated back into roslyn by branching off of
276a8a6 (which is a verbatim copy of the original files updated to include a link to the original source), and then merging the resulting minimized changes back into master. Commit 276a8a6 shows the update from dotnet/runtime@cf258a14 to dotnet/runtime@cb5f173b.