-
Notifications
You must be signed in to change notification settings - Fork 4k
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 PENamespaceSymbol.GetMembers() #73794
Reduce allocations in PENamespaceSymbol.GetMembers() #73794
Conversation
src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamespaceSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamespaceSymbol.cs
Outdated
Show resolved
Hide resolved
…e to allocate for _lazyFlattenedNamespacesAndTypes 2) Place types in _lazyFlattenedNamespacesAndTypes before namespaces to match old behavior
My understanding of the goal of this change is to cache and reuse result produced by this method. If the understanding is correct, then there is an unnecessary churn in this change. I would prefer the change to have the following form:
Refers to: src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamespaceSymbol.cs:67 in 79eb566. [](commit_id = 79eb566, deletion_comment = False) |
Done with review pass (commit 2) |
Can VB implementation benefit from a similar change? |
I've made changes in commit 4 such that I believe the code meets these requests. In reply to: 2142788430 Refers to: src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamespaceSymbol.cs:67 in 79eb566. [](commit_id = 79eb566, deletion_comment = False) |
The GetMembers code in VB appears to already have a single data structure which it can use In reply to: 2142864567 |
@RikkiGibson -- any remaining concerns? |
I am not sure what this means and how it relates to the goal of this PR. It looks to me that result of In reply to: 2143487490 |
It doesn't look like this to me. I was asking to extract the original code without any changes that, in my opinion, are completely unnecessary to achieve the goal of this PR. Then to add cache/reuse logic for the result, but placing the logic outside of the local function. This is what I have in mind.
In reply to: 2143487169 Refers to: src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamespaceSymbol.cs:67 in 79eb566. [](commit_id = 79eb566, deletion_comment = False) |
Done with review pass (commit 3) |
I do like that better. Changing lazyFlattenedNamespacesAndTypes to ImmutableArray made things a bit easier. In reply to: 2146526960 Refers to: src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamespaceSymbol.cs:67 in 79eb566. [](commit_id = 79eb566, deletion_comment = False) |
Yeah, I think we're having a mismatch here. I'm looking at this line: roslyn/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PENamespaceSymbol.vb Line 73 in 824df41
My understanding is that this is the VB equivalent of the code I am modifying in this PR. That code just returns a flattened version of m_lazyMembers, and doesn't combine that with any other data structure. I'd prefer not to change that unless you feel it's necessary. |
What does |
Looks like it takes takes a Dictionary whose values are ImmutableArrays, and flattens those immutable arrays into a single array. |
Is this going to allocate a new ImmutableArray every time? If so, isn't that what we were trying to avoid for C#? The PR title says " |
It certainly is! However, I haven't yet seen a trace implicating this code in VB, whereas I've seen the C# GetMembers call show up in dozens of traces I've looked at. I can indeed take a look at optimizing the VB scenario too, but since it differed from the C# code in this area, I didn't think it within the scope of what I was trying to achieve. |
I can certainly buy this argument
This argument, however, I do not understand. |
src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PENamespaceSymbol.vb
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamespaceSymbol.cs
Outdated
Show resolved
Hide resolved
Done with review pass (commit 5). |
Remove a StaticCast
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 6)
@RikkiGibson, @dotnet/roslyn-compiler For the second review. |
This method commonly shows up in profiles, and this change is very similar to an optimization made to make GetTypeMembers more efficient.
Just opening roslyn.sln and bringing up completion once in a file ends up hitting this codepath about 5,000 times in VS and about 50,000 times OOP. With these changes, I see about 60% of those requests in VS hit the cache, and about 95% of those OOP hit the cache. This is about worst case for hits in this cache too, as PENamespaceSymbol object seemed to be reused quite well.