-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Reduce allocations during SourceGeneration #78403
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
ToddGrun
merged 13 commits into
dotnet:main
from
ToddGrun:dev/toddgrun/SourceGenerationAllocations2
May 7, 2025
Merged
Reduce allocations during SourceGeneration #78403
ToddGrun
merged 13 commits into
dotnet:main
from
ToddGrun:dev/toddgrun/SourceGenerationAllocations2
May 7, 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
SourceGenerator.DoGenerate was previously writing the text into a StringBuilder, wrapping that in a TextReader, and creating a SourceText from that. Creation of that source text would end up allocating in SourceText.From (likely from calling ReadToEnd in the give text reader) Instead, we can use a copy of the (unused) StringBuilderText and just use that as the source text.
Open
3 tasks
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
@dotnet/roslyn-compiler -- PTAL as it looks like this one needs compiler reviews. |
jjonescz
approved these changes
May 6, 2025
src/Tools/Source/CompilerGeneratorTools/Source/CSharpSyntaxGenerator/SourceGenerator.cs
Outdated
Show resolved
Hide resolved
@chsienki PTAL |
chsienki
approved these changes
May 7, 2025
333fred
added a commit
to 333fred/roslyn
that referenced
this pull request
May 8, 2025
* upstream/main: (415 commits) Use lazy initialization for members in CodeFixService (dotnet#78484) Targeted perf changes to CommandLineParser (dotnet#78446) Exclude VS.ExternalAPIs.Roslyn.Package from source-build Add syntax highlighting of ignored directives (dotnet#78458) Fix unexpected conditional state in nullable analysis of conditional access (dotnet#78439) Update RoslynAnalyzers to use Roslyns version Fix source-build by renaming Assets folder to assets Unlist M.CA.AnalyzerUtilities as an expected DevDivInsertion dependency Use a project reference for M.CA.AnalyzerUtilities Rectify status of dictionary expressions (dotnet#78497) Remove unused field Remove unused field Remove using Fix check Update eng/config/PublishData.json Make internal Remove now unused methods from IWorkspaceProjectContext (dotnet#78479) Reduce allocations during SourceGeneration (dotnet#78403) Update Roslyn.sln Merge EditorFeatures.Wpf entirely into EditorFeatures ...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.
SourceGenerator.DoGenerate was previously writing the text into a StringBuilder, wrapping that in a TextReader, and creating a SourceText from that. Creation of that source text would end up allocating in SourceText.From (likely from calling ReadToEnd in the give text reader)
Instead, we can use a copy of the (unused) StringBuilderText class and just use that as the source text.