Skip to content

Developers can safely trim their apps which use System.Text.Json to reduce the size of their apps #45441

Closed

Description

@layomia

There's an ongoing effort (#1568) to use the C# source generator feature to improve start-up performance and reduce private bytes usage during JSON serialization. This same effort can help the linker trim more of System.Text.Json.dll, when used in an application, than it can today. This should reduce the total app size and is important for standalone apps and Blazor client.

Work

Activity

  1. added
    untriaged
    on Dec 1, 2020
  2. removed
    untriaged
    on Dec 1, 2020
  3. added this to the 6.0.0 milestone on Dec 1, 2020
  4. added
    User Story
    tracking
    on Dec 1, 2020
  5. added
    Priority:1
    on Dec 4, 2020
  6. self-assigned this
    on Jan 24, 2021
  7. danmoseley commented on Feb 3, 2021

    @danmoseley
    Contributor

    @layomia I changed this from Proposed to In progress. Hopefully that's correct. It's certainly committed.

  8. layomia commented on Feb 16, 2021

    @layomia
    ContributorAuthor

    @danmoseley - yup it's in progress, and we've started to get some numbers on potential size savings due to having source generation for JSON.

    Now that we can generate code that statically references metadata on input object graphs, we can, based on a prototype linker feature switch (e.g. this snippet):

    Size savings

    This gives us some size savings, based on a simple console app.

    Before: https://github.com/layomia/JsonSourceGenPerf/tree/main/SizeOpts/ConsoleBefore

    After: https://github.com/layomia/JsonSourceGenPerf/tree/main/SizeOpts/ConsoleAfter

    Pre-trimmed STJ.dll (KB) Trimmed STJ.dll (KB) Pre-trimmed App (MB) Trimmed App (MB) Pre-trimmed Application .dll (KB) Trimmed Application .dll (KB)
    .NET 6 - S.T.J (Before) 866 (crossgen'd) 251 63.5 17.5 5 5
    .NET 6 - S.T.J (After) 349 173 63.0 17.2 7 7
    Summary
    • 78K savings to STJ dll size
    • 300K savings to app size

    The major scenario we care about for size is Blazor applications. @tannergooding is helping take measurements and perform analysis for Blazor using the source generator.

  9. layomia commented on Jul 23, 2021

    @layomia
    ContributorAuthor

    With the JSON source generator checked in, we can consider this work done. Please see "Try the new System.Text.Json source generator" for an end-to-end overview of how the generator works and its benefits.

  10. ghost locked as resolved and limited conversation to collaborators on Aug 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Priority:1Team:LibrariesUser Storyarea-System.Text.Jsontracking

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions