Skip to content

Conversation

@Erarndt
Copy link
Contributor

@Erarndt Erarndt commented Jul 15, 2025

Fixes #

Context

There are several delegates called during build that cause some sneaky allocations. For instance, look at the boxing of the BuildRequestEngineStatus enum:

image

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.

Before:

image image image

After:

The UnblockBuildRequest delegate has no allocations
image
image

Changes Made

Testing

Notes

Copilot AI review requested due to automatic review settings July 15, 2025 20:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes performance by reducing boxing allocations and unnecessary array allocations in the BuildRequestEngine. The main issue addressed is the automatic boxing of BuildRequestEngineStatus enum values when passed to ErrorUtilities.VerifyThrow() calls that accept object parameters.

  • Introduces a BuildRequestEngineStatusBoxes class with pre-boxed enum values and an extension method to avoid repeated boxing
  • Updates ErrorUtilities.VerifyThrow() calls to use the new boxing extension method
  • Adds overloaded TraceEngine() methods to prevent array allocations in debugging scenarios

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
IBuildRequestEngine.cs Adds BuildRequestEngineStatusBoxes class with cached boxed enum values and Box() extension method
BuildRequestEngine.cs Updates enum boxing calls and adds overloaded TraceEngine methods to reduce allocations

Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

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

In the future, I'd prefer to see these changes separated out; I found it confusing to see the unrelated changes in the same PR.

@Erarndt
Copy link
Contributor Author

Erarndt commented Jul 16, 2025

In the future, I'd prefer to see these changes separated out; I found it confusing to see the unrelated changes in the same PR.

Curious where/how you'd split this. The paths seemed related to me, so it seemed natural to group them.

@rainersigwald
Copy link
Member

I'd have done

  1. Introduce .Box()
  2. Avoid HasFlag
  3. TraceEngine overloads
  4. Avoid OverallResult when unnecessary

then each is tiny, scoped, and trivial to review. Here I got confused about .Box()'s relationship to the others and wasn't sure whether things were connected.

@rainersigwald rainersigwald enabled auto-merge (squash) July 16, 2025 21:54
@Erarndt
Copy link
Contributor Author

Erarndt commented Jul 16, 2025

I'd have done

  1. Introduce .Box()
  2. Avoid HasFlag
  3. TraceEngine overloads
  4. Avoid OverallResult when unnecessary

then each is tiny, scoped, and trivial to review. Here I got confused about .Box()'s relationship to the others and wasn't sure whether things were connected.

Will do! Thanks for the input

@ghost ghost assigned surayya-MS Aug 6, 2025
Copy link
Member

@YuliiaKovalova YuliiaKovalova left a comment

Choose a reason for hiding this comment

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

Thank you, Eric!

@YuliiaKovalova
Copy link
Member

@Erarndt please address the remaining comments and we are ready to go

@surayya-MS surayya-MS disabled auto-merge August 19, 2025 11:18
@surayya-MS surayya-MS enabled auto-merge (squash) August 19, 2025 11:19
@surayya-MS surayya-MS disabled auto-merge August 19, 2025 11:53
@surayya-MS
Copy link
Member

I'd have done

  1. Introduce .Box()
  2. Avoid HasFlag
  3. TraceEngine overloads
  4. Avoid OverallResult when unnecessary

then each is tiny, scoped, and trivial to review. Here I got confused about .Box()'s relationship to the others and wasn't sure whether things were connected.

Will do! Thanks for the input

@Erarndt do you plan to make changes regarding this comment?
From the code, it seems to me that all 4 are done. So, was it about providing more info about .Box()'s relationship to the others?
I think this is good to merge.

@Erarndt
Copy link
Contributor Author

Erarndt commented Aug 19, 2025

I'd have done

  1. Introduce .Box()
  2. Avoid HasFlag
  3. TraceEngine overloads
  4. Avoid OverallResult when unnecessary

then each is tiny, scoped, and trivial to review. Here I got confused about .Box()'s relationship to the others and wasn't sure whether things were connected.

Will do! Thanks for the input

@Erarndt do you plan to make changes regarding this comment? From the code, it seems to me that all 4 are done. So, was it about providing more info about .Box()'s relationship to the others? I think this is good to merge.

Unless I misunderstood, @rainersigwald requested that I split out the separate changes in the future. No changes requested for this PR.

@rainersigwald
Copy link
Member

Correct. :shipit:

@rainersigwald rainersigwald merged commit 0f8b66d into dotnet:main Aug 19, 2025
9 checks passed
JanProvaznik pushed a commit that referenced this pull request Aug 26, 2025
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.
@Erarndt Erarndt deleted the dev/erarndt/requestStatusBoxing branch September 22, 2025 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants