-
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
Cache the compilation states in compilation order to avoid recalculation #76380
Cache the compilation states in compilation order to avoid recalculation #76380
Conversation
Cache the compilation states in compilation order to avoid recalculation GetStatesInCompilationOrder shows up pretty heavily in CPU usage in the typing scenario in the csharp editing speedometer. The enumerating of the ImmutableList and the repeated searching in the ImmutableSortedDictionary are actually more expensive than one would think. GetStatesInCompilationOrder is optimized out of the profile, but it looks like it is accounting for about 5% of CPU. I'm going to run a test insertion with this change and see what the CPU/memory delta of this method looks like with this change.
@@ -397,6 +397,22 @@ public static ImmutableArray<TResult> SelectAsArray<TSource, TResult>(this IRead | |||
return ImmutableCollectionsMarshal.AsImmutableArray(builder); | |||
} | |||
|
|||
public static ImmutableArray<TResult> SelectAsArray<TSource, TResult, TArg>(this IReadOnlyCollection<TSource>? source, Func<TSource, TArg, TResult> selector, TArg arg) | |||
{ | |||
if (source == null) |
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.
VS Test insertion for speedometer results: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/598012 Run shows similar CPU/Memory in baseline for WithDoNotCreateCreationPolicy With the changes, there is a pretty dramatic difference in CPU usage in WithDoNotCreateCreationPolicy. The ImmutableDictionary/ImmutableList costs in the method are pretty much gone. I do feel like this might have been a lucky run with numbers that were just better, but the WithDoNotCreateCreationPolicy changes are definitely outside the bounds of luck. |
@dotnet/roslyn-compiler ptal |
@CyrusNajmabadi ptal |
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.
Changes under Compilers LGTM (commit 1)
src/Workspaces/Core/Portable/Workspace/Solution/TextDocumentStates.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/Workspace/Solution/TextDocumentStates.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/Workspace/Solution/TextDocumentStates.cs
Outdated
Show resolved
Hide resolved
@dotnet/roslyn-compiler -- need 2nd compiler review (fairly trivial change) |
Cache the compilation states in compilation order to avoid recalculation
GetStatesInCompilationOrder shows up pretty heavily in CPU usage in the typing scenario in the csharp editing speedometer. The enumerating of the ImmutableList and the repeated searching in the ImmutableSortedDictionary are actually more expensive than one would think.
GetStatesInCompilationOrder is optimized out of the profile, but it looks like it is accounting for about 5% of CPU.
I'm going to run a test insertion with this change and see what the CPU/memory delta of this method looks like with this change.
*** CPU in typing scenario in csharp editing speedometer test ***
*** Memory allocations under RegularCompilationTracker.WithDoNotCreateCreationPolicy ***