-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Possible linker removal of JsonDocument and JsonNode (+ ancillary classes) to save 35% of STJ.dll size #51756
Comments
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsA prototype showed a 35% reduction of a trimmed These can be trimmed out if:
The reader\writer do not have any dependencies on these types. The serializer does have dependencies on these but these can be addressed by:
|
Tagging subscribers to 'size-reduction': @eerhardt, @SamMonoRT, @marek-safar, @CoffeeFlux Issue DetailsA prototype showed a 35% reduction of a trimmed These can be trimmed out if:
The reader\writer do not have any dependencies on these types. The serializer does have dependencies on these but these can be addressed by:
|
Since the main scenario for trimming is Blazor client, this suggestion will not help much since the Moving to 7.0 if we want to refactor Blazor to use |
A prototype showed a 35% reduction of a trimmed
System.Text.Json.dll
withJsonDocument
andJsonNode
classes linked out. This also includes ancillary classes likeJsonElement
,JsonObject
,JsonArray
andJsonValue
.There are two scenarios for trimming: one with the JSON source generator used, and one without.
JsonValue
is already trimmed (or should be) if the source generator is used, but not for the non-source generator case.JsonDocument
is never currently trimmed.These can be safely trimmed out if:
[JsonExtensionData]
is not usedSystem.Object
members is not usedJsonNode
classes are not usedJsonDocument
andJsonElement
types are not used.To allow the non-source generator to safely link out
JsonNode
:JsonExtensionDataAttribute
toJsonElement
andJsonNode
to root these types when that feature is used.JsonNode
on the setter toJsonSerializerOptions.UnknownTypeHandling
(default is to useJsonElement
, so the setter must be called to change toJsonNode
) or add alternative API that enables polymorphic (de)serialization in general (see below for potential breaking change).To allow the source generator to link out
JsonDocument
the serializer dependencies can be addressed by:JsonNode
today).JsonNode
today).To allow the non-source generator cases we could introduce a breaking change for polymorphic deserialization of
System.Object
-declared properties\fields\elements:JsonSerializerOptions.UnknownTypeHandling
to add a new default value of "none" (or similar new API).JsonElement
orJsonObject
as a property\field\element instead ofSystem.Object
in order to be explicit and avoid having to setUnknownTypeHandling
.The text was updated successfully, but these errors were encountered: