Skip to content

Allow preinitializing EventSource - #101573

Merged
MichalStrehovsky merged 1 commit into
dotnet:mainfrom
MichalStrehovsky:evtsrcfin
Apr 26, 2024
Merged

Allow preinitializing EventSource#101573
MichalStrehovsky merged 1 commit into
dotnet:mainfrom
MichalStrehovsky:evtsrcfin

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

Contributes to #79204.

We currently don't preinitialize any event sources because they have a finalizer. This is a bit of a problem for places like this:

if (TplEventSource.Log.IsEnabled())
{
TplEventSource.Log.TraceOperationBegin(box.Id, "Async: " + stateMachine.GetType().Name, 0);
}
. We know IsSupported is false so we eliminate the branch, but we still need a cctor check because we access a static (the Log field). The cctor check in a generic method that is instantiated many many many times becomes a death by a thousand papercuts.

Saves 0.7% in size on the stage2 app with EventSource disabled.

Cc @dotnet/ilc-contrib

We currently don't preinitialize any event sources because they have a finalizer. This is a bit of a problem for places like this: https://github.com/dotnet/runtime/blob/5c01ed22b7468a2bee13b498855dcfcc5ae4da50/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs#L229-L232. We know `IsSupported` is false so we eliminate the branch, but we still need a cctor check because we access a static. The cctor check in a generic method that is instantiated many many many times becomes a death by a thousand papercuts.

Saves 0.7% in size on the stage2 app with EventSource disabled.
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

@jkotas jkotas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@MichalStrehovsky
MichalStrehovsky merged commit 0f508f2 into dotnet:main Apr 26, 2024
@MichalStrehovsky
MichalStrehovsky deleted the evtsrcfin branch April 26, 2024 12:58
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
We currently don't preinitialize any event sources because they have a finalizer. This is a bit of a problem for places like this: https://github.com/dotnet/runtime/blob/5c01ed22b7468a2bee13b498855dcfcc5ae4da50/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs#L229-L232. We know `IsSupported` is false so we eliminate the branch, but we still need a cctor check because we access a static. The cctor check in a generic method that is instantiated many many many times becomes a death by a thousand papercuts.

Saves 0.7% in size on the stage2 app with EventSource disabled.
michaelgsharp pushed a commit to michaelgsharp/runtime that referenced this pull request May 9, 2024
We currently don't preinitialize any event sources because they have a finalizer. This is a bit of a problem for places like this: https://github.com/dotnet/runtime/blob/5c01ed22b7468a2bee13b498855dcfcc5ae4da50/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs#L229-L232. We know `IsSupported` is false so we eliminate the branch, but we still need a cctor check because we access a static. The cctor check in a generic method that is instantiated many many many times becomes a death by a thousand papercuts.

Saves 0.7% in size on the stage2 app with EventSource disabled.
@github-actions github-actions Bot locked and limited conversation to collaborators May 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

2 participants