[RAR] GetReferenceFromItemSpec usage can be slow and could be optimized #8281
Labels
backlog
Good First Issue
Self-contained issues good for first-time contributors.
performance
triaged
Issue Description
(
msbuild/src/Tasks/AssemblyDependency/ReferenceTable.cs
Line 1549 in 762ae6c
This method walks through the list of References and checks each against the provided itemSpec to find the one that matches. References is a Dictionary<AssemblyNameExtension, Reference>. It's currently used twice: here and here. In both cases, it's looping over a list of other items. That makes this at least an O(n^2) operation, which is ripe for improvement.
Of note, we don't even necessarily use the AssemblyNameExtension GetReferenceFromItemSpec actually returns; we often just use it to get the Reference associated with it or check to see if we know about it at all.
Fortunately, AssemblyNameExtension implements both IEquatable and GetHashCode. That means that if you can construct a new AssemblyNameExtension with the same hash code that passes that equal check, you can access it directly out of the dictionary. That would turn an O(n^2) operation into an O(n) operation.
Constructing an appropriate ANE isn't trivial, but I think the potential perf win would likely be fairly substantial, so it seems worth looking into to me.
The text was updated successfully, but these errors were encountered: