Avoid unnecessary boxing in calls to EasyTraceEvent #4722
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
There are a multitude of call sites to EventTrace.EasyTraceEvent that pass value type arguments as the param1/param2/param3 arguments, e.g.
wpf/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContext.cs
Line 669 in 5695fbe
wpf/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContext.cs
Line 829 in 5695fbe
These, however, are defined to take
object
, which means the arguments are boxed. And that boxing happens before we even check whether the provider is enabled, as the call sites aren't guarded by checks for IsEnabled. That ends up meaning we potentially do lots of boxing only to immediately find that the data isn't required as tracing is disabled or isn't at a sufficient level. The fix this commit provides is to make these tracing methods generic, such that nothing need be boxed until after we know tracing is enabled.Customer Impact
Less allocation leading to less garbage collection leading to fewer pauses and hiccups in the user experience.
Regression
No
Testing
Just CI
Risk
Minimal. We're simply avoiding some unnecessary work by passing state as generics rather than as object.