-
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
Remove System.Text.Json's DynamicDependencies on Collections.Immutable #53256
Comments
Tagging subscribers to 'size-reduction': @eerhardt, @SamMonoRT, @marek-safar, @CoffeeFlux Issue DetailsToday, Lines 154 to 159 in 5f15498
Lines 186 to 187 in 5f15498
This causes all of the Immutable Collection types to be rooted in an application, even if the app doesn't use the types. This is a fairly substantial amount of code, especially in cases where every KB counts, like Blazor WASM apps. With #53205, I found out that a bunch of other collection types don't work in JsonSerializer in a trimmed app. That makes me think that these Immutable collection types really shouldn't be treated specially, especially considering they bring in so much unused code. I prototyped what it would look like removing these DynamicDependencies here. Using this prototype I was able to measure just how much code these DynamicDependencies are causing: Before: 2,600,754 bytes It decreases the app size almost 28KB .br compressed. With the advent of the JSON source generator, we can make applications that call However, the problem with removing these attributes is that existing apps that use Immutable Collections in a JSON graph would be broken once they are trimmed. For normal apps, we will give them a warning in all places they call the serializer. However, for Blazor WASM apps, these warnings are suppressed by default. So apps won't see them. I can think of the following strategies we could take to resolve this:
In my opinion, using Immutable Collections in a JSON graph isn't a super common case. Paying this price in all apps that use JSON isn't worth the tradeoff. Thoughts? @steveharter @layomia @eiriktsarpalis @jozkee @vitek-karas @marek-safar @SteveSandersonMS @pranavkm @danroth27 @stephentoub @jkotas
|
+1 My vote would be for Option 1 Just remove the DynamicDependencies. |
+1 to Jan's +1. |
I agree and if you also consider other sensitive workloads that would benefit from this and have lower expectations about pre-net6 compatibility it makes even more sense. |
This saves roughly 28 KB compressed in a default blazor wasm app. Fix dotnet#53256
Today,
JsonSerializer
takes aDynamicDependency
on basically all the System.Collection.ImmutableCreateRange
methods:runtime/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactoryHelpers.cs
Lines 154 to 159 in 5f15498
runtime/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactoryHelpers.cs
Lines 186 to 187 in 5f15498
This causes all of the Immutable Collection types to be rooted in an application, even if the app doesn't use the types. This is a fairly substantial amount of code, especially in cases where every KB counts, like Blazor WASM apps.
With #53205, I found out that a bunch of other collection types don't work in JsonSerializer in a trimmed app. That makes me think that these Immutable collection types really shouldn't be treated specially, especially considering they bring in so much unused code.
I prototyped what it would look like removing these DynamicDependencies here. Using this prototype I was able to measure just how much code these DynamicDependencies are causing:
Before: 2,600,754 bytes
After: 2,572,198 bytes
It decreases the app size almost 28KB .br compressed.
With the advent of the JSON source generator, we can make applications that call
JsonSerializer
trim-safe by telling developers to use the source generator when they need to serialize/deserialize objects. If they care about trim-safety, they can convert their code to use the source generator, and it will work, even after trimming.However, the problem with removing these attributes is that existing apps that use Immutable Collections in a JSON graph would be broken once they are trimmed. For normal apps, we will give them a warning in all places they call the serializer. However, for Blazor WASM apps, these warnings are suppressed by default. So apps won't see them.
I can think of the following strategies we could take to resolve this:
In my opinion, using Immutable Collections in a JSON graph isn't a super common case. Paying this price in all apps that use JSON isn't worth the tradeoff.
Thoughts?
@steveharter @layomia @eiriktsarpalis @jozkee @vitek-karas @marek-safar @SteveSandersonMS @pranavkm @danroth27 @stephentoub @jkotas
The text was updated successfully, but these errors were encountered: