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
Using System.Text.Json source generation in my application isn't providing for size reductions in the app because all the JsonConverters are still being rooted in the app.
Similar to #52662, but now because I have the object Value property in my WeatherForecast class.
View the outputted assemblies, and notice that System.Text.Json.dll is ~275KB and still has all its JsonConverters in it.
Analysis
From looking at the results, the reason everything is still rooted is because of the following call graph:
The source gen'd JsonContext class for WeatherForecast has a public JsonTypeInfo<object> Object property that references JsonMetadataServices.ObjectConverter.
JsonMetadataServices.ObjectConverter is a System.Text.Json.Serialization.Converters.ObjectConverter instance.
ObjectConverter takes a direct dependency on JsonNodeConverter.Instance
JsonNodeConverter creates new JsonValue<T>
JsonValue<T>.ToString calls JsonSerializer.Serialize without source gen information
That this point, since JsonSerializer.Serialize is called without source gen information, it now roots all JsonConverters, and the size of the app grows by a lot.
(Note that this pattern exists in ASP.NET Blazor WASM)
Using System.Text.Json source generation in my application isn't providing for size reductions in the app because all the JsonConverters are still being rooted in the app.
Similar to #52662, but now because I have the object Value property in my WeatherForecast class.
View the outputted assemblies, and notice that System.Text.Json.dll is ~275KB and still has all its JsonConverters in it.
Analysis
From looking at the results, the reason everything is still rooted is because of the following call graph:
The source gen'd JsonContext class for WeatherForecast has a public JsonTypeInfo<object> Object property that references JsonMetadataServices.ObjectConverter.
JsonMetadataServices.ObjectConverter is a System.Text.Json.Serialization.Converters.ObjectConverter instance.
ObjectConverter takes a direct dependency on JsonNodeConverter.Instance
JsonNodeConverter creates new JsonValue<T>
JsonValue<T>.ToString calls JsonSerializer.Serialize without source gen information
That this point, since JsonSerializer.Serialize is called without source gen information, it now roots all JsonConverters, and the size of the app grows by a lot.
(Note that this pattern exists in ASP.NET Blazor WASM)
Using System.Text.Json source generation in my application isn't providing for size reductions in the app because all the JsonConverters are still being rooted in the app.
Similar to #52662, but now because I have the
object Value
property in myWeatherForecast
class.Repro
dotnet publish -r win-x64 -c Release -p:PublishTrimmed=true -p:DebuggerSupport=false -p:TrimmerSingleWarn=false
View the outputted assemblies, and notice that
System.Text.Json.dll
is ~275KB and still has all its JsonConverters in it.Analysis
From looking at the results, the reason everything is still rooted is because of the following call graph:
WeatherForecast
has apublic JsonTypeInfo<object> Object
property that referencesJsonMetadataServices.ObjectConverter
.JsonMetadataServices.ObjectConverter
is aSystem.Text.Json.Serialization.Converters.ObjectConverter
instance.ObjectConverter
takes a direct dependency onJsonNodeConverter.Instance
JsonNodeConverter
creates newJsonValue<T>
JsonValue<T>.ToString
callsJsonSerializer.Serialize
without source gen informationThat this point, since
JsonSerializer.Serialize
is called without source gen information, it now roots all JsonConverters, and the size of the app grows by a lot.(Note that this pattern exists in ASP.NET Blazor WASM)
cc @layomia @steveharter @marek-safar @vitek-karas @CoffeeFlux
The text was updated successfully, but these errors were encountered: