Skip to content

Consider stripping names of fields that don't matter #1282

@MichalStrehovsky

Description

@MichalStrehovsky

Now that linker has a pretty good idea what fields are accessed through reflection (and warns whenever its not sure), we could consider stripping names of fields that are not observable.

A field name that is not observable could be defined as:

  • Private field, or field on a private nested type
  • Internal field, or field on an internal type when no InternalsVisibleTo is present
  • Field that linker didn't see as used through reflection
  • Not on a generic type (because of MemberRefs to TypeSpecs).
  • If we have whole program view, we could extend to publics that are not accessed from other assemblies in the closure.

Stripping name means setting accessibility to compilercontrolled (IsCompilerControlled = true in Cecil) and setting name to null.

I experimentally tried this on Mono's WASM CoreLib and saw 1.3% savings. I didn't actually try whether things work. compilercontrolled is such a corner case that I wouldn't be surprised if there's bugs.

It would be more significant if we could do this to methods and types, but it's too easy to get to names of those without linker realizing the name is observable (e.g. o.GetType().FullName for types, or new StackTrace().ToString() for method names).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions