-
Notifications
You must be signed in to change notification settings - Fork 209
Compiler: Optimize SyntaxList<TNode>, SyntaxTokenList and PooledArrayBuilder<T> operations #11909
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
Merged
DustinCampbell
merged 17 commits into
dotnet:main
from
DustinCampbell:syntaxlist-optimizations
Jun 11, 2025
Merged
Compiler: Optimize SyntaxList<TNode>, SyntaxTokenList and PooledArrayBuilder<T> operations #11909
DustinCampbell
merged 17 commits into
dotnet:main
from
DustinCampbell:syntaxlist-optimizations
Jun 11, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It turns out that ImmutableArray<T>.Builder does not provide an InsertRange(...) method that takes a ReadOnlySpan<T> -- though it *does* provide an AddRange(...) overload that takes a ReadOnlySpan<T>. This change adds an extension method for that InsertRange(...) overload.
This change ensures that PooledArrayBuilder<T> provides the same overloads for AddRange(...) and InsertRange(...).
This is now unused.
ToddGrun
reviewed
Jun 7, 2025
src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/ImmutableArrayExtensions.cs
Show resolved
Hide resolved
ToddGrun
reviewed
Jun 7, 2025
src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/PooledObjects/PooledArrayBuilder`1.cs
Show resolved
Hide resolved
chsienki
approved these changes
Jun 9, 2025
Pinging @dotnet/razor-compiler for a second review. |
333fred
approved these changes
Jun 11, 2025
Thanks! |
This was referenced Jun 17, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed that Razor's new
SyntaxTokenList
always creates a new array ofArrayElement<GreenNode>
whenever a mutation method is called, even if there are few enough elements that an array is unnecessary. This pull request addresses that and brings the work done inSyntaxTokenList
toSyntaxList<TNode>
. Here is a summary of the changes:ImmutableArray<T>.Builder.InsertRange(...)
extension method that takes aReadOnlySpan<T>
. For some reason, there's anAddRange
overload forReadOnlySpan<T>
but no matchingInsertRange
overload.PooledArrayBuilder<T>.InsertRange(...)
methods.SyntaxTokenList
to usePooledArrayBuilder<SyntaxToken>
for mutation operations. This should result in fewerArrayElement<GreenNode>[]
allocations.SyntaxList<TNode>
in line withSyntaxTokenList
and usePooledArrayBuilder<TNode>
for mutation operations rather than aList<TNode>
.CI Build: https://dev.azure.com/dnceng/internal/_build/results?buildId=2722495&view=results
Test Insertion: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/640753
Toolset Test Run: https://dev.azure.com/dnceng/internal/_build/results?buildId=2722496&view=results