Skip to content

Trim NetEventSource when EventSource.IsSupported is false #38828

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

Merged
merged 3 commits into from
Jul 9, 2020

Conversation

eerhardt
Copy link
Member

@eerhardt eerhardt commented Jul 6, 2020

Follow up to #38129. NetEventSource code was still left in even when EventSource.IsSupported is false, since all the usages of NetEventSource are keying off its own static property: NetEventSource.IsEnabled.

Remove NetEventSource.IsEnabled so the linker can trim NetEventSource code when EventSource.IsSupported is false.

cc @marek-safar

This trims a little over 8 KB of IL in the CarChecker Blazor app, when EventSource.IsSupported is false.

Build Size
master 3,719,168 bytes
proposed change 3,710,976 bytes

@eerhardt eerhardt requested review from stephentoub and a team July 6, 2020 22:47
@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@ghost
Copy link

ghost commented Jul 6, 2020

Tagging subscribers to this area: @dotnet/ncl
Notify danmosemsft if you want to be subscribed.

@eerhardt
Copy link
Member Author

eerhardt commented Jul 7, 2020

Alternatively, we could just remove NetEventSource.IsEnabled altogether and replace it with NetEventSource.Log.IsEnabled(), which would achieve the same results.
I see that NetEventSource is in a few different assemblies. The alternative route would allow for trimming NetEventSource logic in all the assemblies without having to duplicate the ILLink.Substitutions.xml file for each assembly.

Copy link
Contributor

@alnikola alnikola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are currently migrating from NetEventSources to the new telemetry. It's quite possible that NetEventSources will be eventually completely deleted. Could you please make sure the trimming also works with the new telemetry types? Please, check what has been already done in System.Net.Http #37619 as well the main issue tracking all related work #37428.

@marek-safar
Copy link
Contributor

As the code is located in a common location it'd be better to update the code to follow pattern which can be automatically removed

@alnikola
Copy link
Contributor

alnikola commented Jul 7, 2020

@marek-safar Sorry, it seems I'm missing the point. Could you please clarify which location is a common one? All NetEventSource types are inside System.Net.* projects, so they are not shared with other projects.

@stephentoub
Copy link
Member

stephentoub commented Jul 7, 2020

All NetEventSource types are inside System.Net.* projects, so they are not shared with other projects.

There's NetEventSource.Common.cs, which is built into all of the System.Net.* projects, which then each have their own NetEventSource.SpecificName.cs partial class that provides the actual attribute with the specific name. Any code in common that uses NetEventSource is using the shared definitions.

@eerhardt
Copy link
Member Author

eerhardt commented Jul 7, 2020

As the code is located in a common location it'd be better to update the code to follow pattern which can be automatically removed

Another alternative is to teach the linker to trim this code automatically. I've logged dotnet/linker#1318 for this pattern. If the linker can support it, we shouldn't need to make any change here.

@alnikola
Copy link
Contributor

alnikola commented Jul 7, 2020

@marek-safar Please disregard my above comment. I misunderstood you.

@marek-safar
Copy link
Contributor

There's NetEventSource.Common.cs, which is built into all of the System.Net.* projects

Yep, this PR is fixing the problem for a single assembly but by quick check, it looks like same code is compiled into about 5 other assemblies. They are not Browser critical but still worth considering for other size sensitive configs.

@stephentoub
Copy link
Member

I'm fine with us changing the if (SomeEventSource.IsEnabled) { ... } checks to instead be the more canonical if (SomeEventSource.Log.IsEnabled) { ... } checks. I don't remember why we did the static in the first place; maybe it was a misguided attempt on my part to keep things ever-so-slightly shorter at the call site.

@eerhardt
Copy link
Member Author

eerhardt commented Jul 7, 2020

I'm fine with us changing the if (SomeEventSource.IsEnabled) { ... } checks to instead be the more canonical if (SomeEventSource.Log.IsEnabled) { ... } checks.

I can make that change for all the EventSource classes (thanks @alnikola for the pointers on the new ones coming in) if we decide the linker change (dotnet/linker#1318) is not feasible for 5.0.

cc @vitek-karas

@eerhardt eerhardt force-pushed the TrimNetEventSource branch from eddf3d4 to 6b07aab Compare July 7, 2020 22:46
@eerhardt eerhardt requested a review from a team July 7, 2020 22:46
@eerhardt
Copy link
Member Author

eerhardt commented Jul 7, 2020

I've updated the PR to remove NetEventSource.IsEnabled and HttpTelemetry.IsEnabled static properties since the underlying linker issue isn't a trivial fix and it is unlikely to be fixed for 5.0. I also checked other EventSource implementations in the libraries, and these were the only two with this pattern.

@eerhardt eerhardt requested a review from alnikola July 8, 2020 14:38
@eerhardt eerhardt force-pushed the TrimNetEventSource branch from 7e296cc to a2d2243 Compare July 8, 2020 18:46
@eerhardt eerhardt dismissed alnikola’s stale review July 8, 2020 18:48

New approach taken.

eerhardt added 3 commits July 9, 2020 09:14
Follow up to dotnet#38129. NetEventSource code was still left in even when EventSource.IsSupported is false, since all the usages of NetEventSource are keying off its own static property: NetEventSource.IsEnabled.

Remove NetEventSource.IsEnabled so the linker can trim NetEventSource code when EventSource.IsSupported is false.
… EventSource code when EventSource.IsSupported is false.
@eerhardt eerhardt force-pushed the TrimNetEventSource branch from a2d2243 to 821f3ad Compare July 9, 2020 14:14
@@ -145,7 +145,7 @@ private void CheckForShutdown()

_ = _connectionClosedTask.ContinueWith(closeTask =>
{
if (closeTask.IsFaulted && NetEventSource.IsEnabled)
if (closeTask.IsFaulted && NetEventSource.Log.IsEnabled())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the clauses here aren't swapped, will the linker end up making this if (closeTask.IsFaulted) { } or will it be able to eliminate the whole if block, regardless?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linker will eliminate the conditionally guarded block, any conditions guarding it will be untouched.

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I skimmed through the changes. At this point it's "just" changing if (NetEventSource.IsEnabled) to be if (NetEventSource.Log.IsEnabled) in the tons of places that occurs, right? Just wanted to make sure I didn't miss anything more critical. Assuming so, LGTM.

@eerhardt
Copy link
Member Author

eerhardt commented Jul 9, 2020

At this point it's "just" changing if (NetEventSource.IsEnabled) to be if (NetEventSource.Log.IsEnabled) in the tons of places that occurs, right?

Correct. The changes were:

  1. Remove the static new bool IsEnabled properties from NetEventSource and HttpTelemetry classes.
  2. Massive Find and Replace XXEventSource.IsEnabled to XXEventSource.Log.IsEnabled()
  3. Fix one fake/mock NetEventSource class in the tests (this is the third commit)

@stephentoub stephentoub merged commit 98eee05 into dotnet:master Jul 9, 2020
@eerhardt eerhardt deleted the TrimNetEventSource branch July 9, 2020 18:14
@karelz karelz added this to the 5.0.0 milestone Aug 18, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants