From 302a8790528524f251482a10e88d7fc2fece8aef Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 22 Jun 2021 23:29:26 -0400 Subject: [PATCH] Avoid unnecessary boxing in calls to EasyTraceEvent There are a multitude of call sites to EventTrace.EasyTraceEvent that pass value type arguments as the param1/param2/param3 arguments. 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. --- .../src/Shared/MS/Utility/Trace.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/Trace.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/Trace.cs index 5a58400bfa7..04e218d9222 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/Trace.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/Trace.cs @@ -50,7 +50,7 @@ static internal void EasyTraceEvent(Keyword keywords, Level level, Event eventID // EasyTraceEvent // Checks the keyword and level before emiting the event - static internal void EasyTraceEvent(Keyword keywords, Event eventID, object param1) + static internal void EasyTraceEvent(Keyword keywords, Event eventID, T1 param1) { if (IsEnabled(keywords, Level.Info)) { @@ -60,7 +60,7 @@ static internal void EasyTraceEvent(Keyword keywords, Event eventID, object para // EasyTraceEvent // Checks the keyword and level before emiting the event - static internal void EasyTraceEvent(Keyword keywords, Level level, Event eventID, object param1) + static internal void EasyTraceEvent(Keyword keywords, Level level, Event eventID, T1 param1) { if (IsEnabled(keywords, level)) { @@ -70,7 +70,7 @@ static internal void EasyTraceEvent(Keyword keywords, Level level, Event eventID // EasyTraceEvent // Checks the keyword and level before emiting the event - static internal void EasyTraceEvent(Keyword keywords, Event eventID, object param1, object param2) + static internal void EasyTraceEvent(Keyword keywords, Event eventID, T1 param1, T2 param2) { if (IsEnabled(keywords, Level.Info)) { @@ -78,7 +78,7 @@ static internal void EasyTraceEvent(Keyword keywords, Event eventID, object para } } - static internal void EasyTraceEvent(Keyword keywords, Level level, Event eventID, object param1, object param2) + static internal void EasyTraceEvent(Keyword keywords, Level level, Event eventID, T1 param1, T2 param2) { if (IsEnabled(keywords, Level.Info)) { @@ -88,7 +88,7 @@ static internal void EasyTraceEvent(Keyword keywords, Level level, Event eventID // EasyTraceEvent // Checks the keyword and level before emiting the event - static internal void EasyTraceEvent(Keyword keywords, Event eventID, object param1, object param2, object param3) + static internal void EasyTraceEvent(Keyword keywords, Event eventID, T1 param1, T2 param2, T3 param3) { if (IsEnabled(keywords, Level.Info)) {