Further reduce allocations in CreateGraphNodeAsync #5593
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug
Related: NuGet/Home#12748
Regression? Last working version:
Description
This PR makes additional changes to reduce allocations in
CreateGraphNodeAsync()
by addressing three issues highlighted in this trace:A
LightweightList
was introduced in a previous PR to reduce the need to allocate aList<T>
in the cases where the number of items was 4 or fewer. This value was chosen because it was seen as a safe starting point since it's the default size forList<T>
as well as the 80th percentile in telemetry data50 - 2,
70 - 3,
80 - 4
90 - 7
95 - 9
This trace indicates that there are still significant allocations occurring and this change allows
LightweightList
to contain up to 10 items before needing to allocate aList<T>
.The second change introduces a helper method on
GraphNode
that enables callers to ensure thatInnerNodes
has sufficient capacity to add additional items to minimize resizing.Finally,
FindRuntimeDependencies()
often returns aList<T>
wrapped by theIEnumerable<T>
interface which was resulting in boxing of theList<T>.Enumerator
. The existingNoAllocEnumerate()
helper can be used here to avoid the boxing.PR Checklist
PR has a meaningful title
PR has a linked issue.
Described changes
Tests
Documentation