You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
The text was updated successfully, but these errors were encountered:
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.StackTraceHiddenAttributedotnet/runtime#29681; though probably not significant?
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).
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:
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, ornew StackTrace().ToString()
for method names).The text was updated successfully, but these errors were encountered: