-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Lookup/ItemDictionary make up a huge amount of allocations/CPU item #2587
Comments
📝 As of this writing, the collections referenced in this comment are in their earliest stages (API review), but I'm keeping an eye open for cases where they may help solve real-world problems. 💡
|
Having spent a non-trivial time walking through this code, I'm convinced that ItemDictionary/Lookup needs to be rethought/rewritten with more appropriate collections. 11% of allocations and 6.5% comes from Lookup. We spent a large non-trivial amount of time creating and merging collections, huge amount of allocations are us resizing the underlying Dictionary<TKey, TValue> because we couldn't figure out the up-front size. I'm going to change this bug to be about that. |
Just interesting why the hell Dictionary needs to be resized? Can't instead of resizing we allocate just another array and use list of arrays instead of a single? |
Tradeoff - that would increase the size of Dictionary, and eventually something has to increase the size of the list of arrays and we're back to square one. Though that would help avoiding the large object heap- but if your dictionary is 85k you're probably better off with a different object. |
You don't have to use List to store Arrays, simple linked list would be enough here. Anyway any collection is good at some particular use case. E.g. if collection is resized a lot then that collection is probably a bad choice for that scenario? PS: Can't we specify Capacity here? |
I'm assuming you don't mean a linked link as the entire back storing (which would be O(n) lookup) but rather as the store for the underlying arrays. If so, yes, that's heading towards Immutable collection territory - which is what I'm thinking. I've made changes to set capacity in places - but we due to the way it was written, we don't know how much data we're going to add these dictionaries by the end of the scopes of evaluation, so we can't pick the "right size". |
Note @davkean 's request was implemented for .NET Core 2.1, so for that target you can call EnsureCapacity |
Labeling with size:1 as the cost of the initial investigation. Will open a follow-up issue if more work is identified. |
12/2021 numbers as measured when clean-building the Ocelot solution:
Not as bad anymore but definitely worth optimizing. |
Back to backlog as I will not have time to work on this in the near future. |
What's happening is that the initial capability/current capability is not correct, and we're resizing the underlying items dictionary, possible multiple times with the same ImportItems call.
Not sure of a good way to fix this - there's no way to resize a dictionary after it's created.
The text was updated successfully, but these errors were encountered: