Skip to content

Dependency resolver allocating and resizing HashSet #14611

@jeffkl

Description

@jeffkl

NuGet Product Used

MSBuild.exe, NuGet.exe, dotnet.exe

Product Version

17.14

Worked before?

No response

Impact

It bothers me. A fix would be nice

Repro Steps & Context

PRISM is showing that this is a top allocation bug

https://prism.vsdata.io/failure/?eventType=Allocation&failureHash=f91dc5e1-bfea-70c1-5f3f-4b56a80af227

Warning: This is AI-generated content and may be inaccurate.

Brief description

Issue type: Collections — DO specify an up-front capacity if one is known
Description: On the hot leaf path in ResolveDependencyGraphItemsAsync, a HashSet named suppressions is lazily initialized without capacity. This set is populated within a loop over chosenResolvedItem.Item.Data.Dependencies, causing potential internal resizes and allocations. We can derive an appropriate initial capacity from chosenResolvedItem.Item.Data.Dependencies.Count and pass it at construction to reduce allocations on this hot path.
Proposed fix: Initialize the HashSet with capacity using chosenResolvedItem.Item.Data.Dependencies.Count when it is first created.

Verbose Logs

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions