-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Avoid allocations in AbstractSyntaxIndex<>.GetIndexAsync #74075
Conversation
s_documentToIndex.TryAdd(document, index); | ||
s_documentIdToIndex.AddOrUpdate(document.Id, index); | ||
#else | ||
// Avoid capturing index on the fast path by making a copy for the slow path |
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.
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.
It could, but it wouldn't be less net code. Creating a temporary local is pretty standard practice for this.
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.
OK, I've never noticed it done this way whereas I've seen it done the other way a couple times.
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.
The NET part lgtm. I don't get the value in the local copy. We'll still have the closure allocation there afaict
The problem isn't the closure allocation when used. The problem is it still creates a closure allocation for |
How does the local copy help there? Can you show the il diff? Thanks! |
Here's a SharpLab example: The key difference is the "original" code has a
While the "copy" code only has it after calling
|
Further improves a scenario that also suggested it will be improved by #73493.
Based on allocations observed in AB#2090900.