Skip to content
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

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

Open
MichalStrehovsky opened this issue Jun 18, 2020 · 2 comments
Open

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

MichalStrehovsky opened this issue Jun 18, 2020 · 2 comments
Labels
Milestone

Comments

@MichalStrehovsky
Copy link
Member

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).

@benaadams
Copy link
Member

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

Could strip method names marked with System.Diagnostics.StackTraceHiddenAttribute dotnet/runtime#29681; though probably not significant?

@MichalStrehovsky
Copy link
Member Author

Could strip method names marked with System.Diagnostics.StackTraceHiddenAttribute dotnet/runtime#29681; though probably not significant?

That would help a little bit, but we would also have to prove the address of the method wasn't taken (e.g. we didn't create a delegate that someone could call GetMethodInfo on - because that becomes visible too).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

5 participants