-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Reduce allocations in NamespaceSymbol.GetExtensionContainers #78243
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
Reduce allocations in NamespaceSymbol.GetExtensionContainers #78243
Conversation
…ordered Going to create a test insertion to get numbers before moving out of draft mode. Will add performance justification of the change at that point.
…ontainers virtual and having MergedNamespaceSymbol implement it directly.
|
@dotnet/roslyn-compiler -- This is ready for review |
|
|
||
| protected void AddExtensionContainersForType(NamedTypeSymbol type, ArrayBuilder<NamedTypeSymbol> extensions) | ||
| { | ||
| if (!type.IsReferenceType || !type.IsStatic || type.IsGenericType || !type.MightContainExtensionMethods) return; |
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.
That's not an obvious equivalence (for me, at least). I'd prefer not to make that change, but will if you would like me to.
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.
Consider at least adding a comment capturing the suggestion and starting with // Tracked by https://github.com/dotnet/roslyn/issues/76130 :
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.
Done in commit 5
| } | ||
| } | ||
|
|
||
| protected void AddExtensionContainersForType(NamedTypeSymbol type, ArrayBuilder<NamedTypeSymbol> extensions) |
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.
"AddExtensionContainersFromType" or "AddExtensionContainersInType"? #Closed
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.
Done in commit 4
AlekseyTs
left a comment
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.
LGTM (commit 3)
AlekseyTs
left a comment
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.
LGTM (commit 4)
Reduce allocations from executing NamespaceSymbol.GetExtensionContainers. This method accounts for 48% of allocations in our CodeAnalysis process during completion in our C# editing speedometer test. The changes in this PR reduce that to about 4.5%
The change here is to add an override of NamespaceSymbol.GetExtensionContainers to MergedNamespaceSymbol. Specifically, the base class implementation of GetExtensionContainers calls GetTypeMembersUnordered, which is inefficient when in a MergedNamespaceSymbol instance as it does a Linq OfType call and allocates an IA from that. Instead, the new override can just enumerate over the result of GetMembersUnordered directly, and do the check before calling into shared code with the base implementation.
*** Previous allocations during completion section of C# editing speedometer test ***

*** New allocations in NamespaceSymbol.GetTypeMembersUnordered ***

*** New allocations in MergedNamespaceSymbol.GetTypeMembersUnordered ***
