-
Notifications
You must be signed in to change notification settings - Fork 2.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
Optimize Small Dictionaries #10733
Optimize Small Dictionaries #10733
Conversation
… Set intial dictionary capacity where known.
Hi there @nzdev, thank you for this contribution! 👍 While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:
Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution. If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request. Thanks, from your friendly Umbraco GitHub bot 🤖 🙂 |
…nto v8/feature/adaptive-dictionary
public dictionaries may need to remain dictionaries as due to casting / is operator to Dictionary instead of IDictionary fails (ModelsBuilder community version) |
Hiya @nzdev! We wanted to thank you for your work and let you know that we have spent some time reviewing the contribution and have decided that we are going to close this one. We appreciate that you have worked hard to build and document this contribution to create the changes you want to see but given the status of Umbraco 8, moving into LTS and Umbraco 9 being ready and stable and packed with new features, we are working through the open PRs and deciding which are a good fit for the last version 8 minor and which are not. If you'd like to know a little more about this process, please check out this blog post, explaining how we came to the decisions we have made here. We'd like to reassure you though that the CMS team, along with some special guests, took the time to assess each PR that is being closed and decided how to proceed - whilst the message you're receiving is automatic, the work behind it was done by the people that make up the CMS team, along with community members. If there are specifics around this PR that you'd like explained that are not covered by the article, please let us know. All the best to you, our wonderful contributor. Thanks, from your friendly Umbraco GitHub bot 🤖 🙂 |
Prerequisites
If there's an existing issue for this PR then this fixes
Description
Port AdaptiveCapacityDictionary from dotnet/aspnetcore#31360 which uses an array internally for capacity < 10, then uses a Hashtable once capacity >=10. This saves on memory and improves speed for small dictionaries.
Changes:
Use AdaptiveCapacityDictionary where appropriate.
Set Dictionary/AdaptiveCapacityDictionary inital capacity where known
Change from Dictionary to IDictionary where private/internal as required.
How to test?
Unit tests and benchmarks ported from dotnet/aspnetcore#31360.
Existing Umbraco tests pass.
Benchmarks:
// * Summary *
BenchmarkDotNet=v0.11.3, OS=Windows 10.0.19043
Intel Core i7-10750H CPU 2.60GHz, 1 CPU, 12 logical and 6 physical cores
[Host] : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.8.4390.0
Job-FTOBUC : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.8.4390.0
InvocationCount=1 UnrollFactor=1
SixValues_SmallDictGetGet | 200.00 ns | 11.54 ns | 30.19 ns | 210.0000 ns | 210.0 ns |
SevenValues_SmallDictGetGet | 278.18 ns | 39.68 ns | 116.38 ns | 260.0000 ns | 470.0 ns |
EightValues_SmallDictGet | 265.00 ns | 22.68 ns | 63.98 ns | 290.0000 ns | 390.0 ns |
NineValues_SmallDictGet | 323.85 ns | 27.78 ns | 77.90 ns | 270.0000 ns | 470.0 ns |
TenValues_SmallDictGet | 300.43 ns | 33.83 ns | 96.52 ns | 260.0000 ns | 460.0 ns |
TenValues_DictGet | 439.84 ns | 21.75 ns | 61.71 ns | 485.0000 ns | 525.0 ns |
SmallDict | 1,020.00 ns | 191.76 ns | 565.40 ns | 705.0000 ns | 1,905.0 ns |
Dict | 1,308.47 ns | 199.45 ns | 588.08 ns | 976.4700 ns | 2,181.5 ns |
SmallDictFour | 1,034.00 ns | 193.78 ns | 571.37 ns | 670.0000 ns | 1,920.0 ns |
DictFour | 1,285.00 ns | 218.60 ns | 644.56 ns | 915.0000 ns | 2,320.0 ns |
SmallDictTen | 1,023.00 ns | 226.80 ns | 668.73 ns | 610.0000 ns | 2,115.0 ns |
DictTen | 1,345.00 ns | 199.83 ns | 589.19 ns | 1,010.0000 ns | 2,320.0 ns |