-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Randomize analyzer instantiation to avoid static constructor/jit contention #69838
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
Conversation
src/Compilers/Core/Portable/InternalUtilities/EnumerableExtensions.cs
Outdated
Show resolved
Hide resolved
| builder[swapIndex] = builder[i]; | ||
| } | ||
|
|
||
| builder.Free(); |
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.
Not loving that this whole algorithm was written out twice.
src/Workspaces/Core/Portable/Diagnostics/HostDiagnosticAnalyzers.cs
Outdated
Show resolved
Hide resolved
333fred
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.
I do wonder a bit about whether this will fully fix contention (I think it may be likely that users don't have that many analyzer assemblies, and the analyzers within an assembly will share some number of helper types, so randomizing may help a bit, but still have contention in the shared helper types), but I'm willing to give it a try and see if it helps.
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerFileReference.cs
Outdated
Show resolved
Hide resolved
|
@dotnet/roslyn-compiler Could I have another compiler review please? Thanks! |
I'm seeing 4 types of contention:
I'm fairly hopeful that randomization will have a pretty good impact on the top two, unsure about the last two yet. Update: Spin waiting contention (ie CPU) was in ~60% of all solution load traces, and that doesn't factor in in sync (blocked) time. |
| } | ||
|
|
||
| return analyzers.ToImmutable(); | ||
| analyzers.Sort(static (x, y) => string.Compare(x.typeName, y.typeName, StringComparison.OrdinalIgnoreCase)); |
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.
Since we are sorting here, I changed the type of analyzerTypeNames to ImmutableHashSet from ImmutableSortedSet
Fixing internal bug https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1880870