Skip to content

Lookup.ExplicitModifications switch to concrete dictionary type for enumerator.#11985

Merged
YuliiaKovalova merged 4 commits intodotnet:mainfrom
ttstanley:users/tevinstanley/applymetadataboxingenumerator
Oct 13, 2025
Merged

Lookup.ExplicitModifications switch to concrete dictionary type for enumerator.#11985
YuliiaKovalova merged 4 commits intodotnet:mainfrom
ttstanley:users/tevinstanley/applymetadataboxingenumerator

Conversation

@ttstanley
Copy link
Contributor

@ttstanley ttstanley commented Jun 10, 2025

Context

When building a smaller solution we can see the boxing to IEnumerator pop up for 0.1% allocations
image

Changes Made

Switched from returning IEnumerator to the underlying dictionary type to allow usage of the struct enumerator to prevent boxing.

@ttstanley ttstanley marked this pull request as ready for review June 25, 2025 17:43
Copilot AI review requested due to automatic review settings June 25, 2025 17:43
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 updates the ExplicitModifications property in Lookup.cs to return a concrete Dictionary instead of an IEnumerable, optimizing performance by leveraging a struct enumerator to prevent boxing.

  • Changed the ExplicitModifications property return type from IEnumerable<KeyValuePair<string, MetadataModification>> to Dictionary<string, MetadataModification>.
  • Aims to reduce allocations during enumeration by avoiding boxing.
Comments suppressed due to low confidence (1)

src/Build/BackEnd/Components/RequestBuilder/Lookup.cs:1183

  • The XML documentation summary for ExplicitModifications still mentions 'an enumeration of the explicit metadata modifications'. Consider updating the summary to reflect that a Dictionary is returned, which may improve clarity for other developers.
            public Dictionary<string, MetadataModification> ExplicitModifications

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