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

Fix trimming for DiagnosticSource #106680

Merged
merged 2 commits into from
Aug 22, 2024
Merged

Conversation

noahfalk
Copy link
Member

Recent changes to EventSource startup caused the IL trimmer to include portions of the DiagnosticSource assembly. Adding the IsMeterSupported feature check wasn't sufficient because EventSource also roots all of its methods via a DynamicallyAccessedMembers attribute. To ensure that the new methods can be removed when needed I refactored them into a separate EventSourceInitHelper class that won't be rooted by the existing DAM attribute.

When EventSouce.IsSupported is false I'd expect the entire EventSourceInitHelper class to be unreachable. If only EventSource.IsMeterSupported is false then I'd expect PreregisterEventProviders and GetMetricsEventSource() to be unreachable but the rest of the class will remain.

Hopefully this really fixes #106265 this time.

Recent changes to EventSource startup caused the IL trimmer to include portions of the DiagnosticSource assembly. Adding the IsMeterSupported feature check wasn't sufficient because EventSource also roots all of its methods via a DynamicallyAccessedMembers attribute. To ensure that the new methods can be removed when needed I refactored them into a separate EventSourceInitHelper class that won't be rooted by the existing DAM attribute.

When EventSouce.IsSupported is false I'd expect the entire EventSourceInitHelper class to be unreachable. If only EventSource.IsMeterSupported is false then I'd expect PreregisterEventProviders and GetMetricsEventSource() to be unreachable but the rest of the class will remain.

Hopefully this really fixes dotnet#106265 this time.
@noahfalk
Copy link
Member Author

noahfalk commented Aug 20, 2024

@MichalStrehovsky
@vitek-karas

Vitek, in the issue you also mentioned "So I found first bug - the substitution doesn't define default value, so if the feature switch is not defined at all (which is the default), no substitution happens. We'll have to add featuredefaultvalue to the XML to fix this."

My current PR doesn't have any changes to the XML and it wasn't clear what was needed. I've never messed with 'featuredefault' before, my understanding so far is just cobbled together from looking at other examples and I found the ILLinker code which I think processes it. From what I can tell other switches as well as the 'System.Diagnostics.Metrics.Meter.IsSupported' switch used from the DiagnosticSource assembly are already configured to act as though unspecified is the same as enabled. So it seemed like the new XML I previously added is also consistent with that pattern. If something should change there please let me know!

@MichalStrehovsky
Copy link
Member

Hopefully this really fixes #106265 this time.

I think this will. I've run rt-sz measurements on this PR and the results are:

(Look at the labels to see what each one is measuring - MichalStrehovsky/rt-sz#66 is the most interesting because it's EventSourceSupport=true MetricsSupport=false and it's showing 150-300 kB savings across the board.)

@vitek-karas
Copy link
Member

Vitek, in the issue you also mentioned "So I found first bug - the substitution doesn't define default value, so if the feature switch is not defined at all (which is the default), no substitution happens. We'll have to add featuredefaultvalue to the XML to fix this."

Sorry this is outdated. I thought we didn't want the feature to be enabled by default, since I've learned that is not the case for desktop - at least right now. So you don't need featuredefault for that case.

@noahfalk
Copy link
Member Author

Thanks for the review and feedback. All the suggestions have been applied.

@vitek-karas
Copy link
Member

I validated that this resolves the regression on the app where we diagnosed it with Matous originally (iOS sample mono app in runtime repo).

@noahfalk
Copy link
Member Author

I validated that this resolves the regression on the app where we diagnosed it with Matous originally (iOS sample mono app in runtime repo).

Glad to hear it 👍
I think this is ready to be merged. It just needs someone to mark it approved.

@noahfalk noahfalk merged commit 6177a9f into dotnet:main Aug 22, 2024
147 checks passed
@noahfalk
Copy link
Member Author

/backport to release/9.0

Copy link
Contributor

Started backporting to release/9.0: https://github.com/dotnet/runtime/actions/runs/10516341520

@sebastienros
Copy link
Member

Visible startup time improvement after this change.

image

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

Successfully merging this pull request may close these issues.

[mono][size][Perf] iOS and Android size regression on 8/9/2024 8:00:01 AM
5 participants