Skip to content

Blazor Wasm - Size regression in System.Text.Json.dll  #51311

Closed

Description

@SamMonoRT

Activity

  1. added
    arch-wasmWebAssembly architecture
    size-reductionIssues impacting final app size primary for size sensitive workloads
    on Apr 15, 2021
  2. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Apr 15, 2021
  3. changed the title [-]Blazor Wasm - Size regression in System.Json.Text.dll [/-] [+]Blazor Wasm - Size regression in System.Text.Json.dll [/+] on Apr 15, 2021
  4. eerhardt commented on Apr 15, 2021

    @eerhardt
    Member

    @eerhardt suggested that these 2 changes are possible offenders

    #50778
    #51025

    @layomia @steveharter @eiriktsarpalis

  5. layomia commented on Apr 16, 2021

    @layomia
    Contributor

    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.

  6. SamMonoRT commented on Apr 16, 2021

    @SamMonoRT
    MemberAuthor

    Thanks @layomia - do we know if there is any tracking issue for the refactoring work ?

  7. SamMonoRT commented on Apr 16, 2021

    @SamMonoRT
    MemberAuthor

    cc @mkArtakMSFT - is this on your team ?

  8. SamMonoRT commented on Apr 16, 2021

    @SamMonoRT
    MemberAuthor

    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.

  9. added this to the 6.0.0 milestone on Apr 19, 2021
  10. steveharter commented on Apr 21, 2021

    @steveharter
    Contributor

    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:

    internal class MyCustomContext : JsonSerializerContext
    {
        public MyCustomContext(JsonSerializerOptions options) : base(options) { }
        // Also possible to cache\expose the JsonTypeInfos here...
    }
    
    JsonSerializerOptions options = new JsonSerializerOptions;
    options.Converters.Add(JsonConverters.String);
    options.Converters.Add(JsonConverters.Int32);
    options.Converters.Add(JsonConverters.JsonNodeConverterFactory);
    // etc
    
    var context = new MyCustomContext(options);
    JsonNode node = ...
    JsonSerializer.Serialize(node, context);
  11. SamMonoRT commented on Apr 27, 2021

    @SamMonoRT
    MemberAuthor

    Assigning to @layomia for tracking based on additional work building over the JSON SourceGenerator work

  12. layomia commented on May 17, 2021

    @layomia
    Contributor

    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

  13. lewing commented on Jul 31, 2021

    @lewing
    Member

    Is there any remaining .NET6 work here?

  14. layomia commented on Aug 9, 2021

    @layomia
    Contributor

    I believe there's no work left here for 6.0 given the above plan #51311 (comment). cc @eerhardt

  15. modified the milestones: 6.0.0, 7.0.0 on Aug 9, 2021
  16. modified the milestones: 7.0.0, Future on Jul 10, 2022
  17. eiriktsarpalis commented on Sep 2, 2022

    @eiriktsarpalis
    Member

    I think we can close this issue now?

  18. ghost locked as resolved and limited conversation to collaborators on Oct 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-wasmWebAssembly architecturearea-System.Text.Jsonsize-reductionIssues impacting final app size primary for size sensitive workloads

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions