You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Blazor Wasm - Size regression in System.Text.Json.dll #51311
These two changes are primarily JsonConverter-based features and are very likely to have caused the regression.
The JSON source generator will help reduce size for apps that use the new overloads that take pre-generated metadata (#51300). The converters for these features will be trimmed out if not needed in an app, and if the new serializer methods are used instead of the existing ones.
I don't expect the size regression here to be reversed until the JSON serialization logic within Blazor assemblies is refactored to use the new serializer methods. See these commits for an early attempt. Happy to help with this effort.
Want to put this note out, to make it very clear - We don't expect any changes from dotnet/aspnetcore#31877 to be backported to Preview 4. But we need to make sure the necessary work has a timeline to make it in quickly.
One potential path to reduce size as new features (and converters) are added is to initialize JsonSerializerOptions with no converters and then add only the converters necessary for the given application and scenarios. @layomia recently added the source-gen \ trimming work that does this but it could be extended and used without source-gen:
internalclassMyCustomContext:JsonSerializerContext{publicMyCustomContext(JsonSerializerOptionsoptions):base(options){}// Also possible to cache\expose the JsonTypeInfos here...}JsonSerializerOptionsoptions=newJsonSerializerOptions;options.Converters.Add(JsonConverters.String);options.Converters.Add(JsonConverters.Int32);options.Converters.Add(JsonConverters.JsonNodeConverterFactory);// etcvarcontext=newMyCustomContext(options);JsonNodenode= ...JsonSerializer.Serialize(node,context);
Following up on offline discussions on email, I'm noting on this issue that the path to reducing the regression here will not be about Blazor fully adopting the JSON source generator internally and in the default template (dotnet/aspnetcore#31877). Size is important for Blazor, but it was discussed that the generator should focus on trim safety (already supported), and improve (de)serialization throughput (in progress with #51945).
For mitigating the size regression here, this issue will instead focus on internal System.Text.Json changes to reduce the assembly size when source gen is not used:
Activity
[-]Blazor Wasm - Size regression in System.Json.Text.dll [/-][+]Blazor Wasm - Size regression in System.Text.Json.dll [/+]eerhardt commentedon Apr 15, 2021
@eerhardt suggested that these 2 changes are possible offenders
#50778
#51025
@layomia @steveharter @eiriktsarpalis
layomia commentedon Apr 16, 2021
These two changes are primarily
JsonConverter-based features and are very likely to have caused the regression.The JSON source generator will help reduce size for apps that use the new overloads that take pre-generated metadata (#51300). The converters for these features will be trimmed out if not needed in an app, and if the new serializer methods are used instead of the existing ones.
I don't expect the size regression here to be reversed until the JSON serialization logic within Blazor assemblies is refactored to use the new serializer methods. See these commits for an early attempt. Happy to help with this effort.
SamMonoRT commentedon Apr 16, 2021
Thanks @layomia - do we know if there is any tracking issue for the refactoring work ?
SamMonoRT commentedon Apr 16, 2021
cc @mkArtakMSFT - is this on your team ?
SamMonoRT commentedon Apr 16, 2021
Want to put this note out, to make it very clear - We don't expect any changes from dotnet/aspnetcore#31877 to be backported to Preview 4. But we need to make sure the necessary work has a timeline to make it in quickly.
steveharter commentedon Apr 21, 2021
One potential path to reduce size as new features (and converters) are added is to initialize
JsonSerializerOptionswith no converters and then add only the converters necessary for the given application and scenarios. @layomia recently added the source-gen \ trimming work that does this but it could be extended and used without source-gen:SamMonoRT commentedon Apr 27, 2021
Assigning to @layomia for tracking based on additional work building over the JSON SourceGenerator work
layomia commentedon May 17, 2021
Following up on offline discussions on email, I'm noting on this issue that the path to reducing the regression here will not be about Blazor fully adopting the JSON source generator internally and in the default template (dotnet/aspnetcore#31877). Size is important for Blazor, but it was discussed that the generator should focus on trim safety (already supported), and improve (de)serialization throughput (in progress with #51945).
For mitigating the size regression here, this issue will instead focus on internal System.Text.Json changes to reduce the assembly size when source gen is not used:
cc @SamMonoRT @CoffeeFlux @eerhardt @steveharter @ericstj @SteveSandersonMS @pranavkm @jkotas
lewing commentedon Jul 31, 2021
Is there any remaining .NET6 work here?
layomia commentedon Aug 9, 2021
I believe there's no work left here for 6.0 given the above plan #51311 (comment). cc @eerhardt
eiriktsarpalis commentedon Sep 2, 2022
I think we can close this issue now?