- Notifications
You must be signed in to change notification settings - Fork 5.2k
Event listener overhead reduction pt. 3 #52455
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
Conversation
Store PayloadNames on EventMetadata instead of EventWrittenEventArgs
| Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti Issue DetailsBuilding on top of #51822 and #52092.
Should be all from me around EventSource for a while. I'll put up a PR to get some of these benchmarks in the performance repo.
|
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs Outdated Show resolved Hide resolved
| { | ||
| #if !ES_BUILD_STANDALONE | ||
| [RequiresUnreferencedCode(EventSourceRequiresUnreferenceMessage)] | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| { | ||
| Guid activityId = m_activityId; | ||
| if (activityId == Guid.Empty) | ||
| if (_moreInfo is MoreEventInfo moreInfo && moreInfo.ActivityId != Guid.Empty) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens to performance if you add TplEventSource keyword=0x80 to the trace which enables activity tracking? Even if the Yarp telemetry doesn't enable the keyword there is a decent (and growing) chance that some other EventSource session will enable it and the effects are global. I'm worried that it may be a common scenario that causes EventListener to fall off the fast path in which case it may be better to add ActivityId (but not RelatedActivityId) to the default field set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How common is it for users to enable activity tracking while using in-process EventListeners as well?
The perf wouldn't be much worse in that case (an extra object allocation). If you believe using EventListener and 0x80 at the same time is common enough I can move the ActivityId off of ExtraInfo as you suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My guess is that the usage would be uncorrelated, but if both are independently common enough then there could still be significant overlap - this is just educated guessing on my part. If the perf consequence isn't that meaningful then there is no need to worry, but I assumed you wouldn't have done the optimization at all if it didn't make a difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Method | Toolchain | Mean | Error | Ratio | Gen 0 | Allocated |
|---|---|---|---|---|---|---|
| WriteEventNoParams | OnExtraInfo | 55.46 ns | 1.125 ns | 1.00 | 0.0134 | 56 B |
| WriteEventNoParams | OnBaseObject | 53.52 ns | 0.420 ns | 0.96 | 0.0172 | 72 B |
| WriteEventNoParams_ActivityId | OnExtraInfo | 84.18 ns | 0.631 ns | 1.00 | 0.0401 | 168 B |
| WriteEventNoParams_ActivityId | OnBaseObject | 77.48 ns | 0.679 ns | 0.92 | 0.0172 | 72 B |
| FullYarpRequest | OnExtraInfo | 1,939.21 ns | 38.206 ns | 1.00 | 0.7744 | 3241 B |
| FullYarpRequest | OnBaseObject | 1,948.20 ns | 20.337 ns | 1.00 | 0.8469 | 3545 B |
| FullYarpRequest_ActivityId | OnExtraInfo | 5,101.87 ns | 85.053 ns | 1.00 | 2.4490 | 10266 B |
| FullYarpRequest_ActivityId | OnBaseObject | 4,558.92 ns | 31.574 ns | 0.89 | 1.6022 | 6713 B |
Moved it back onto the base object.
Looks like a measurable improvement for the case when ActivityId is accessed while not really affecting other cases.
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs Outdated Show resolved Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read this one when it first went up, but apparently forgot to hit the approve button! Thanks!
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs Outdated Show resolved Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| Failure: #11063 |
Building on top of #51822 and #52092.
Reduced the size of
EventWrittenEventArgsfor the common caseEventSource,EventId,TimeStampandPayload.MoreInfoclass that's allocated only if more parameters are set:Stored
ParameterNamesonEventMetadatainstead ofEventWrittenEventArgsAvoided duplication around
TraceLoggingEventTypes293538eBenchmarks.cs
Should be all from me around EventSource for a while.
PR adding a subset of these benchmarks to the performance repo: dotnet/performance#1800