[release/6.0-rc1] Make JsonGenerator be an incremental generator (#57088) #58278
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.
Backport of #57088 to release/6.0-rc1
Contributes to #56702
Customer Impact
Customers are reporting sluggish IDE behavior when targeting net6.0 in large solutions.
This change is converting the System.Text.Json source generator to use the new
IIncrementalGenerator
Roslyn API. This allows for the source generator to do considerably less work in the background of the IDE, especially when no code in the solution uses the source generator.Testing
All automated tests continue to pass.
I also tested manually using VS 2022 that the source generator still works after converting to the new Roslyn API.
The responsiveness of VS 2022 in a large solution on my
Standard_D8as_v4
Azure VM went from ~2 seconds to open the Intellisense window to almost instantaneous.Risk
Since the
IIncrementalGenerator
Roslyn API is new in Roslyn v4.0, it doesn't work in VS 2019. This means a customer using the 6.0-rc1 NuGet package in VS 2019 will get a warning:Warning CS8032 An instance of analyzer System.Text.Json.SourceGeneration.JsonSourceGenerator cannot be created from C:\Users\eerhardt\.nuget\packages\system.text.json\7.0.0-dev\analyzers\dotnet\cs\System.Text.Json.SourceGeneration.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
The plan is to enable "multi-targeting" different Roslyn versions in 6.0-rc2. This will allow us to ship 2 versions of the source generator in the NuGet package - one targeting the 3.x Roslyn APIs and one targeting the 4.0 Roslyn APIs, with the performance of the 4.0 Roslyn version being much better.
cc @chsienki @ericstj @jaredpar @sharwell