Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Cache RetargetingParameterSymbol.TypeWithAnnotations to avoid ~8.3% allocations in a trace #69011
Cache RetargetingParameterSymbol.TypeWithAnnotations to avoid ~8.3% allocations in a trace #69011
Changes from 1 commit
90ec1a6
ca72dde
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Nullable<TypeWithAnnotations>
is not thread-safe. Is this field accessed from multiple threads?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.
@cston Yeah I was chatting with Sam about this. I didn't find an appropriate existing helper, so Sam is working on merging helpers that are not available in the compilers layer with those available in the compilers layer.
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.
No additional helpers are necessary, that's what https://sourceroslyn.io/#Microsoft.CodeAnalysis.CSharp/Symbols/TypeWithAnnotations.cs,e5078e3d5fd03b05,references is for.
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.
If the goal is to avoid recalculating the type, it may be sufficient to just cache the
TypeSymbol
.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.
@cston In the trace I provided, this property is accessed 12,833,732 times during 3 minutes. So I think it's worth to just cache the whole thing.
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.
Does this suggest it like that?
I think that would still risk calculating it twice if two threads concurrently accessed the property.
What Sam suggested was something to be like 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.
@333fred The helpers are lazy initialization helpers for reference types, and are unrelated to the fact that this is a value type. Even after switching to
TypeWithAnnotations.Boxed
, we'd want to use the helper method for clarity. See #69017There 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.
We should switch to
TypeWithAnnotations.Boxed
, which we use to cache this information in symbols. There should be many examples. No special helpers are necessary and the change shouldn't be blocked on that.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.
I used
TypeWithAnnotations.Boxed
for now. After #69017 is merged, I can switch to another helper if that would be better.