-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Use dictionary to track PackageRelationships instead of searching a list #35978
Use dictionary to track PackageRelationships instead of searching a list #35978
Conversation
Tagging subscribers to this area: @jozkee |
I ran some performance tests locally and see the following:
Not sure where to add performance tests to the repo. Unit tests already cover the functional side of things. |
@carlossanlop Looks like you may own this area of code. Can you take a look? |
src/libraries/System.IO.Packaging/src/System/IO/Packaging/InternalRelationshipCollection.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Packaging/src/System/IO/Packaging/OrderedDictionary.cs
Show resolved
Hide resolved
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.
Thanks for submitting this change, @twsouthwick. I left a couple of comments.
62e4f38
to
1d3cd0f
Compare
src/libraries/System.IO.Packaging/src/System/IO/Packaging/OrderedDictionary.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Packaging/src/System/IO/Packaging/OrderedDictionary.cs
Outdated
Show resolved
Hide resolved
|
||
public bool Remove(TKey key) | ||
{ | ||
if (_dictionary.TryGetValue(key, out var value)) |
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.
Can this use the Remove overload that gives back the associated value as an out? Then we wouldn't need the below call to Remove and would avoid the secondary lookup.
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 has to compile against .NET Standard 1.3 and 2.0 and that's not available. Should I do an #if/#def?
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.
Probably not worth it just for this.
src/libraries/System.IO.Packaging/src/System/IO/Packaging/InternalRelationshipCollection.cs
Show resolved
Hide resolved
src/libraries/System.IO.Packaging/src/System/IO/Packaging/OrderedDictionary.cs
Show resolved
Hide resolved
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.
A few questions/comments, but otherwise looks good.
The CI build got deprovisioned. /azp run runtime |
Hello @twsouthwick! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
Thanks for contributing, @twsouthwick ! |
Thanks @twsouthwick! 🎉 |
This change adds an OrderedDictionary<TKey,TValue> type to System.IO.Packaging to keep a list of relationships that have been added, while ensuring that the ids are unique with decent performance characteristics. The current implementation searches a list which gets really slow with large numbers of relationships. A Dictionary by itself does not work for this as the order of addition is important. Thus, this combines a LinkedList to track the order, while a Dictionary is used to for quick look up of existing items.
Fixes #983