-
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
Make the impl of SyntaxNode.GetText more efficient #73512
Conversation
this.WriteTo(new StringWriter(builder)); | ||
return new StringBuilderText(builder, encoding, checksumAlgorithm); | ||
var fullWidth = this.Green.FullWidth; | ||
var writer = SourceTextWriter.Create(encoding, checksumAlgorithm, fullWidth); |
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.
this helper gets an appropriate writer depending on the length of the final source text. For <85k (the loh limit) you get a simple string writer. For >85k you get a chunking writer.
@@ -238,87 +236,6 @@ public static SourceText ReadFrom(ITextFactoryService textService, ObjectReader | |||
return textService.CreateText(textReader, encoding, checksumAlgorithm, cancellationToken); | |||
} | |||
|
|||
public static SourceText CreateSourceText( |
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.
IDE impl that can be entirely removed now that the compiler side is just smarter.
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.
This also means we avoid the IDE making an entire copy of the node into our chunks, which then the compiler makes a copy of when making its LargeText instance itself.
@@ -48,8 +48,7 @@ public override SourceText GetText(CancellationToken cancellationToken) | |||
{ | |||
if (_lazyText == null) | |||
{ | |||
var sourceText = SourceTextExtensions.CreateSourceText(GetRoot(cancellationToken), Encoding, _checksumAlgorithm, cancellationToken); | |||
Interlocked.CompareExchange(ref _lazyText, sourceText, null); | |||
Interlocked.CompareExchange(ref _lazyText, GetRoot(cancellationToken).GetText(Encoding, _checksumAlgorithm), 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.
can just delegate to compiler, now that it is not inefficient.
@dotnet/roslyn-compiler for review. This is a tiny change in the impl here, with a big net win for IDE scenarios. BIG :D |
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
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.
The existing impl woudl always allocation into the LOH for large trees. This manifested as huge growth in the LOH for normal IDE scenarios (like 'fix all'):
With this change, we drop to:
--
Total char[] allocs also drops from:
To: