Skip to content
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

[RAR] GetReferenceFromItemSpec usage can be slow and could be optimized #8281

Open
Forgind opened this issue Jan 5, 2023 · 1 comment
Open
Labels
backlog Good First Issue Self-contained issues good for first-time contributors. performance triaged

Comments

@Forgind
Copy link
Member

Forgind commented Jan 5, 2023

Issue Description

(

internal AssemblyNameExtension GetReferenceFromItemSpec(string itemSpec)
)

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.

@Forgind Forgind added performance needs-triage Have yet to determine what bucket this goes in. labels Jan 5, 2023
@AR-May AR-May added backlog Good First Issue Self-contained issues good for first-time contributors. and removed needs-triage Have yet to determine what bucket this goes in. labels Jan 17, 2023
@stan-sz
Copy link
Contributor

stan-sz commented Jan 31, 2023

Linking to #2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Good First Issue Self-contained issues good for first-time contributors. performance triaged
Projects
None yet
Development

No branches or pull requests

4 participants