Skip to content

Avoid enumerator boxing for ItemBucket #11929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2025

Conversation

Erarndt
Copy link
Contributor

@Erarndt Erarndt commented May 29, 2025

Fixes #

The ItemBucket constructor enumerates some dictionary keys through the ICollection interface that causes allocations by boxing an enumerator.

Context

The only type that's passed to the constructor is a dictionary and we pass the associated KeyCollection which ends up getting boxed. We can just pass the concrete type to avoid this.

image

Changes Made

Testing

Notes

@Copilot Copilot AI review requested due to automatic review settings May 29, 2025 21:12
Copy link
Contributor

@Copilot 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 aims to improve performance by avoiding enumerator boxing when iterating over dictionary keys for the ItemBucket constructor.

  • Updated the ItemBucket constructor parameter type to use Dictionary’s KeyCollection directly.
  • Adjusted unit tests to pass the concrete KeyCollection.

Reviewed Changes

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

File Description
src/Build/BackEnd/Components/RequestBuilder/ItemBucket.cs Changed parameter type to avoid enumerator boxing for performance.
src/Build.UnitTests/BackEnd/TaskExecutionHost_Tests.cs Updated test initialization to match the new constructor parameter type.
Comments suppressed due to low confidence (1)

src/Build/BackEnd/Components/RequestBuilder/ItemBucket.cs:77

  • While the change improves performance by avoiding boxing, ensure that exposing the concrete KeyCollection type fits within the long-term API design, as it may limit flexibility if future needs require a broader abstraction.
Dictionary<string, ICollection<ProjectItemInstance>>.KeyCollection itemNames, // PERF: directly use the KeyCollection to avoid boxing the enumerator.

@YuliiaKovalova YuliiaKovalova merged commit d0d0b2b into dotnet:main Jun 2, 2025
10 checks passed
@Erarndt Erarndt deleted the dev/erarndt/keyCollection branch June 10, 2025 18:21
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.

3 participants