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
Outdated
Show resolved
Hide resolved
carlossanlop
left a comment
There was a problem hiding this comment.
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.
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.
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.
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
stephentoub
left a comment
There was a problem hiding this comment.
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