-
Notifications
You must be signed in to change notification settings - Fork 212
Compiler: Replace SyntaxListBuilder with PooledArrayBuilder<T> and miscellaneous performance tweaks #11841
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
Add a handful of extension methods for PooledArrayBuidler<TNode> that facilitate constructing green syntax list nodes and red syntax lists.
This change includes fairly substantial refactoring of the methods on SyntaxUtilities, and changes all methods to use PooledArrayBuilder<T> rather than other collections.
This change updates the syntax API for Razor to add two abstract types: - BaseMarkupStartTagSyntax - inherited by MarkupStartTagSyntax and MarkupTagHelperStartTagSyntax - BaseMarkupEndTagSyntax - inherited by by MarkupEndTagSyntax and MarkupTagHelperEndTagSyntax The IStartTagSyntaxNode and IEndTagSyntaxNode interfaces have been removed.
GreenNode.WriteTo(...) performs three loops for each node: 1. Find the first non-null slot index. 2. Find the last non-null slot index. 3. Loop from the last non-null slot index to the first non-null slow index and push non-null children. These loops don't really perform any additional work, but the extra complexity doesn't add any value either.
Introduce SyntaxNode.DescendantTokens(...) to avoid building a string for each attribute's content just to check string.IsNullOrWhitespace.
😍😍😍 |
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.
✅ Tooling changes are awesome
@@ -42,7 +41,7 @@ public async Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(RazorC | |||
// We also check for tag helper start tags here, because an invalid start tag with a valid tag helper | |||
// anywhere in it would otherwise not match. We rely on the IsTagUnknown method below, to ensure we | |||
// only offer on actual potential component tags (because it checks for the compiler diagnostic) | |||
var startTag = (IStartTagSyntaxNode?)node.FirstAncestorOrSelf<SyntaxNode>(n => n is IStartTagSyntaxNode); | |||
var startTag = node.FirstAncestorOrSelf<BaseMarkupStartTagSyntax>(); |
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.
Thank you! This is literally the dream I had when I created that interface. If only I'd known how, and was brave enough, to use the syntax generator :)
This change is primarily about removing the
Syntax.SyntaxListBuilder
andSyntax.SyntaxListBuilder<T>
from the compiler and replacing usages withPooledArrayBuilder<T>
. This allows the compiler to use stack memory for small lists and only acquire pooled heap memory for larger lists.In addition, I've made several other changes and some small refactorings along the way. In particular, I've introduced
BaseMarkupStartTagSyntax
andBaseMarkupEndTagSyntax
types to share code between the normal markup tag syntax types and their tag helper variants.CI Build: https://dev.azure.com/dnceng/internal/_build/results?buildId=2704937&view=results
Test Insertion: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/635185
Toolset Test Run: https://dev.azure.com/dnceng/internal/_build/results?buildId=2704938&view=results#SourceCard