From 61f024157f39808a2ff45789cf26742817e89d2b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 31 Mar 2026 01:14:58 +0000 Subject: [PATCH 1/2] perf: reuse ResizeArray buffer in chunkBy and chunkByAsync 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> --- release-notes.txt | 1 + src/FSharp.Control.TaskSeq/TaskSeqInternal.fs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/release-notes.txt b/release-notes.txt index 7078840..9fb0961 100644 --- a/release-notes.txt +++ b/release-notes.txt @@ -2,6 +2,7 @@ Release notes: 1.0.0 + - perf: TaskSeq.chunkBy and chunkByAsync reuse the ResizeArray buffer between chunks, reducing allocations on sequences with many chunk boundaries - fixes: TaskSeq.insertAt, insertManyAt, removeAt, removeManyAt, updateAt now raise ArgumentNullException (not NullReferenceException) when given a null source; insertManyAt also validates the values argument - refactor: simplify lengthBy and lengthBeforeMax to use while! and remove the redundant mutable 'go' and initial MoveNextAsync - adds TaskSeq.distinctUntilChangedWith and TaskSeq.distinctUntilChangedWithAsync, #345 diff --git a/src/FSharp.Control.TaskSeq/TaskSeqInternal.fs b/src/FSharp.Control.TaskSeq/TaskSeqInternal.fs index cc279c1..261dbba 100644 --- a/src/FSharp.Control.TaskSeq/TaskSeqInternal.fs +++ b/src/FSharp.Control.TaskSeq/TaskSeqInternal.fs @@ -1754,7 +1754,7 @@ module internal TaskSeqInternal = currentChunk.Add item else yield prevKey, currentChunk.ToArray() - currentChunk <- ResizeArray<'T>() + currentChunk.Clear() // reuse backing array; ToArray() already captured a snapshot currentChunk.Add item maybeCurrentKey <- ValueSome key @@ -1782,7 +1782,7 @@ module internal TaskSeqInternal = currentChunk.Add item else yield prevKey, currentChunk.ToArray() - currentChunk <- ResizeArray<'T>() + currentChunk.Clear() // reuse backing array; ToArray() already captured a snapshot currentChunk.Add item maybeCurrentKey <- ValueSome key From 4ce009ba7f5eb2e7cc75353f8420fd5816677ac5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 31 Mar 2026 01:15:01 +0000 Subject: [PATCH 2/2] ci: trigger checks