-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Consider creating new dictionary type which allocates an array for small capacities instead of an entire dictionary #31290
Comments
Confirmed that RouteValueDictionary allocates less bytes by default than a Dictionary (40 bytes vs 66 bytes). @JamesNK thoughts on using RouteValueDictionary in more places where we expect small amounts of values in a dictionary? |
Be careful to check it's protected against hash collision attacks if any user data goes near it. |
Thanks for contacting us. |
Kestrel's IFeatureCollections use a |
The concept you're interested in with The actual |
No hashing involved. Keys are matched by looping over all the items in the dictionary. O(n) world. |
Ah hence for "very small" collections :) |
Yeah, I did a quick test with RouteValueDictionary and it seemed to be fine, but agree we should create a new type. |
We allocate a lot of dictionaries across ASP.NET Core, which have a non-zero allocation cost to them. An interesting idea would be to see if we could use an array internally for smaller sizes.
We already do this today in Routing: https://github.com/dotnet/aspnetcore/blob/main/src/Http/Http.Abstractions/src/Routing/RouteValueDictionary.cs. I think we could probably use RouteValueDictionary (or a copy of it) in different places across the stack.
The text was updated successfully, but these errors were encountered: