Skip to content

Trimming System.SR #46940

Open
Open

Description

Issue

System.SR is currently one of the largest types when looking at the trimmer dependency dump. As of 6.0.100-alpha.1.21057.4 it is reported at 23470 bytes.

System.SR exists of over a thousand small properties that are effectively just internal static string Name => GetResourceString("Name");. Given that each of these methods actually uses a different string constant, they each take up their own space in metadata and each user ends up having a call to the relevant method.

I think there are two feasible fixes we could have here...

Proposal 1

We specially annotate the properties and have the IL Linker inline these at the usage site. Given that every one of these methods is auto-generated today and that they always follow the same format, this should be generally "safe" (and I believe similar to the NonVersionable attribute).

Proposal 2

We rework how resources are resolved so that, rather than going through a property (SR.Name) we do something like SR.GetResourceString(nameof(SRID.Name)) instead.

A local prototype of this (proposal 2) for S.P.Corelib in the default blazor-wasm project template shows a size reduction in System.Private.CoreLib.dll.br of 6.4kb (and a reduction of 26.5kb for the uncompressed S.P.Corelib).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    area-Metasize-reductionIssues impacting final app size primary for size sensitive workloads

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions