Conversation
Previously, each time a new chunk was started in chunkBy/chunkByAsync, a fresh ResizeArray was allocated. Since ToArray() already captures an independent copy of the data, the internal buffer can be safely reused by calling Clear() instead of constructing a new ResizeArray. This eliminates one heap allocation per chunk boundary, reducing GC pressure for sequences with many distinct runs. 5017 tests pass, 2 skipped. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
9 tasks
dsyme
approved these changes
Apr 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🤖 This is an automated pull request from Repo Assist.
Summary
TaskSeq.chunkByandTaskSeq.chunkByAsyncpreviously allocated a freshResizeArray<'T>at every chunk boundary:Since
ToArray()already creates an independent copy of the chunk contents, the existingResizeArraybacking array can be safely reused by callingClear()instead:Root Cause
ResizeArray<'T>()allocates a new object on the heap (with default initial capacity 4).Clear()simply sets the internal count to zero and retains the existing backing array. BecauseToArray()captures a snapshot before the clear, the yielded arrays are unaffected.Impact
ResizeArrayallocation per chunk boundaryTest Status
dotnet build— succeeded, 0 warningsdotnet test— 5017 passed, 2 skipped (skipped tests are pre-existing infrastructure-only skips)dotnet fantomas . --check— no issues