You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Avoid boxing and unnecessary array allocations (#12175)
There are several delegates called during build that cause some sneaky
allocations. For instance, there is boxing of the `BuildRequestEngineStatus` enum.
The culprit is the `ErrorUtilities.VerifyThrow()` calls that take
`object` as parameters for the formatted message. To make the call, the
enum gets boxed even when the condition check returns `true`. Adding
additional overloads that take the specific type lets multiple callers
benefit, and I did some additional cleanup in the delegates to remove
some allocations.
Copy file name to clipboardExpand all lines: src/Build/BackEnd/Components/BuildRequestEngine/BuildRequestEngine.cs
+97-8Lines changed: 97 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -343,7 +343,7 @@ public void SubmitBuildRequest(BuildRequest request)
343
343
QueueAction(
344
344
()=>
345
345
{
346
-
ErrorUtilities.VerifyThrow(_status!=BuildRequestEngineStatus.Shutdown&&_status!=BuildRequestEngineStatus.Uninitialized,"Engine loop not yet started, status is {0}.",_status);
346
+
ErrorUtilities.VerifyThrow(_status!=BuildRequestEngineStatus.Shutdown&&_status!=BuildRequestEngineStatus.Uninitialized,"Engine loop not yet started, status is {0}.",_status.Box());
347
347
TraceEngine("Request {0}({1}) (nr {2}) received and activated.",request.GlobalRequestId,request.ConfigurationId,request.NodeRequestId);
348
348
349
349
ErrorUtilities.VerifyThrow(!_requestsByGlobalRequestId.ContainsKey(request.GlobalRequestId),"Request {0} is already known to the engine.",request.GlobalRequestId);
@@ -363,7 +363,7 @@ public void SubmitBuildRequest(BuildRequest request)
@@ -414,7 +414,7 @@ public void UnblockBuildRequest(BuildRequestUnblocker unblocker)
414
414
QueueAction(
415
415
()=>
416
416
{
417
-
ErrorUtilities.VerifyThrow(_status!=BuildRequestEngineStatus.Shutdown&&_status!=BuildRequestEngineStatus.Uninitialized,"Engine loop not yet started, status is {0}.",_status);
417
+
ErrorUtilities.VerifyThrow(_status!=BuildRequestEngineStatus.Shutdown&&_status!=BuildRequestEngineStatus.Uninitialized,"Engine loop not yet started, status is {0}.",_status.Box());
418
418
ErrorUtilities.VerifyThrow(_requestsByGlobalRequestId.ContainsKey(unblocker.BlockedRequestId),"Request {0} is not known to the engine.",unblocker.BlockedRequestId);
@@ -467,7 +467,11 @@ public void UnblockBuildRequest(BuildRequestUnblocker unblocker)
467
467
}
468
468
else
469
469
{
470
-
TraceEngine("Request {0}({1}) (nr {2}) is no longer waiting on nr {3} (UBR). Results are {4}.",entry.Request.GlobalRequestId,entry.Request.ConfigurationId,entry.Request.NodeRequestId,result.NodeRequestId,result.OverallResult);
470
+
// PERF: Explicitly check the debug flag here so that we don't pay the cost for getting OverallResult
471
+
if(_debugDumpState)
472
+
{
473
+
TraceEngine("Request {0}({1}) (nr {2}) is no longer waiting on nr {3} (UBR). Results are {4}.",entry.Request.GlobalRequestId,entry.Request.ConfigurationId,entry.Request.NodeRequestId,result.NodeRequestId,result.OverallResult);
474
+
}
471
475
472
476
// Update the configuration with targets information, if we received any and didn't already have it.
473
477
if(result.DefaultTargets!=null)
@@ -515,7 +519,7 @@ public void ReportConfigurationResponse(BuildRequestConfigurationResponse respon
515
519
QueueAction(
516
520
()=>
517
521
{
518
-
ErrorUtilities.VerifyThrow(_status!=BuildRequestEngineStatus.Shutdown&&_status!=BuildRequestEngineStatus.Uninitialized,"Engine loop not yet started, status is {0}.",_status);
522
+
ErrorUtilities.VerifyThrow(_status!=BuildRequestEngineStatus.Shutdown&&_status!=BuildRequestEngineStatus.Uninitialized,"Engine loop not yet started, status is {0}.",_status.Box());
519
523
520
524
TraceEngine("Received configuration response for node config {0}, now global config {1}.",response.NodeConfigurationId,response.GlobalConfigurationId);
0 commit comments