Skip to content

Conversation

@MihaZupan
Copy link
Member

@MihaZupan MihaZupan commented Apr 24, 2021

  • When writing events with no payload (just event id), avoid allocating an empty object[] and ReadOnlyCollection for the EventWrittenEventArgs payload
  • In WriteEventWithRelatedActivityIdCore, avoid fetching metadata from m_eventData[eventId] multiple times
  • In DecodeObject, remove the const bool m_EventSourcePreventRecursion = false and the logic around flipping a m_EventSourceInDecodeObject ThreadStatic we would always ignore because of m_EventSourcePreventRecursion anyway
  • Avoid fetching payload type from within DecodeObject itself, pass it in instead (so we don't re-fetch metadata for each parameter)
  • Instead of recalculatnig the expected parameter count on every call to WriteToAllListeners, do it once and store the value in EventMetadata (EventListenerParameterCount)

Net result: save 2 object allocations when writing events with no payload, save some cycles in all cases

Benchmark.cs

Method Toolchain Mean Error StdDev Median Ratio Gen 0 Allocated
WriteEventNoParams base 79.86 ns 1.524 ns 1.426 ns 79.50 ns 1.00 0.0440 184 B
WriteEventNoParams new 64.50 ns 1.227 ns 2.844 ns 64.01 ns 0.78 0.0324 136 B
WriteEventIntParams base 198.66 ns 3.903 ns 6.837 ns 195.68 ns 1.00 0.0668 280 B
WriteEventIntParams new 134.20 ns 2.711 ns 3.619 ns 133.30 ns 0.67 0.0668 280 B
WriteEventStringParams base 527.01 ns 6.637 ns 6.208 ns 526.14 ns 1.00 0.0744 312 B
WriteEventStringParams new 433.64 ns 5.706 ns 5.338 ns 433.57 ns 0.82 0.0744 312 B

@ghost
Copy link

ghost commented Apr 24, 2021

Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti
See info in area-owners.md if you want to be subscribed.

Issue Details
  • When writing events with no payload (just event id), avoid allocating an empty object[] and ReadOnlyCollection for the EventWrittenEventArgs payload
  • In WriteEventWithRelatedActivityIdCore, avoid fetching metadata from m_eventData[eventId] multiple times
  • In DecodeObject, remove the const bool m_EventSourcePreventRecursion = false and the logic around flipping a m_EventSourceInDecodeObject ThreadStatic we would always ignore because of m_EventSourcePreventRecursion anyway
  • Avoid fetching payload type from within DecodeObject itself, pass it in instead (so we don't re-fetch metadata for each parameter)
  • Instead of recalculatnig the expected parameter count on every call to WriteToAllListeners, do it once and store the value in EventMetadata (EventListenerParameterCount)

Net result: save 2 object allocations when writing events with no payload, save some cycles in all cases

Method Toolchain Mean Error StdDev Median Ratio Gen 0 Allocated
WriteEventNoParams base 79.86 ns 1.524 ns 1.426 ns 79.50 ns 1.00 0.0440 184 B
WriteEventNoParams new 64.50 ns 1.227 ns 2.844 ns 64.01 ns 0.78 0.0324 136 B
WriteEventIntParams base 198.66 ns 3.903 ns 6.837 ns 195.68 ns 1.00 0.0668 280 B
WriteEventIntParams new 134.20 ns 2.711 ns 3.619 ns 133.30 ns 0.67 0.0668 280 B
WriteEventStringParams base 527.01 ns 6.637 ns 6.208 ns 526.14 ns 1.00 0.0744 312 B
WriteEventStringParams new 433.64 ns 5.706 ns 5.338 ns 433.57 ns 0.82 0.0744 312 B
Author: MihaZupan
Assignees: -
Labels:

area-System.Diagnostics.Tracing

Milestone: 6.0.0

Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

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

Thanks @MihaZupan, looks good to me aside from tweaking the comment

@noahfalk
Copy link
Member

cc @josalem @davmason @sywhang

@MihaZupan MihaZupan merged commit 52c1d0b into dotnet:main Apr 28, 2021
@noahfalk
Copy link
Member

Thanks for the perf improvements @MihaZupan!
cc @stephentoub

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.

4 participants