-
Notifications
You must be signed in to change notification settings - Fork 221
Further reduce allocations in SemanticToken calculations #12206
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
Further reduce allocations in SemanticToken calculations #12206
Conversation
Instead of realizing ImmutableArrays in several codepaths, we can instead just have the code append the new items to an existing list. Also, in ConvertSemanticRangesToSemanticTokensData, switches to optimistically allocating an int[] instead of a pooled list for two reasons: 1) In almost all cases, the correct size is calculated before population 2) The pooled list that was being created ended up being too large to be placed back in the pool, so we ended up losing both that list and it's backing array to GC.
davidwengier
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.
Other than the build errors and some naming tweaks, this makes sense to me.
...ks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensBenchmark.cs
Outdated
Show resolved
Hide resolved
...osoft.CodeAnalysis.Razor.Workspaces/SemanticTokens/AbstractRazorSemanticTokensInfoService.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/SemanticTokens/SemanticTokensVisitor.cs
Outdated
Show resolved
Hide resolved
|
Test insertion run from commit 4 didn't have expected gains. Looks like the test is using a larger page than I was testing against. Switched to a custom pool which should work better against larger sematic token request. Test insertion queued for new numbers. |
...osoft.CodeAnalysis.Razor.Workspaces/SemanticTokens/AbstractRazorSemanticTokensInfoService.cs
Outdated
Show resolved
Hide resolved
...osoft.CodeAnalysis.Razor.Workspaces/SemanticTokens/AbstractRazorSemanticTokensInfoService.cs
Outdated
Show resolved
Hide resolved
...osoft.CodeAnalysis.Razor.Workspaces/SemanticTokens/AbstractRazorSemanticTokensInfoService.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/SemanticTokens/SemanticTokensVisitor.cs
Outdated
Show resolved
Hide resolved
...osoft.CodeAnalysis.Razor.Workspaces/SemanticTokens/AbstractRazorSemanticTokensInfoService.cs
Outdated
Show resolved
Hide resolved
...osoft.CodeAnalysis.Razor.Workspaces/SemanticTokens/AbstractRazorSemanticTokensInfoService.cs
Show resolved
Hide resolved
...osoft.CodeAnalysis.Razor.Workspaces/SemanticTokens/AbstractRazorSemanticTokensInfoService.cs
Outdated
Show resolved
Hide resolved
...osoft.CodeAnalysis.Razor.Workspaces/SemanticTokens/AbstractRazorSemanticTokensInfoService.cs
Outdated
Show resolved
Hide resolved
...osoft.CodeAnalysis.Razor.Workspaces/SemanticTokens/AbstractRazorSemanticTokensInfoService.cs
Outdated
Show resolved
Hide resolved
...osoft.CodeAnalysis.Razor.Workspaces/SemanticTokens/AbstractRazorSemanticTokensInfoService.cs
Outdated
Show resolved
Hide resolved
|
@DustinCampbell -- I think I liked every single suggestion you made! Thanks! |
DustinCampbell
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.
🚀
Instead of realizing ImmutableArrays in several codepaths, we can instead just have the calculations append items to an existing list.
Also, in ConvertSemanticRangesToSemanticTokensData, switches to optimistically allocating an int[] instead of a pooled list for two reasons:
This wasn't a huge memory hitter for me in the profile I'm looking at, but still is ~0.6% of allocations in the RoslynCodeAnalysisService process during the C#/html completions in the razor cohosting speedometer test.
Test insertion: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/669091
Numbers looked good in the test insertion: SemanticRange[] allocations pretty much gone, and the int[] allocations in ConvertSemanticRangesToSemanticTokensData are down significantly too.