Skip to content

Commit 24c7791

Browse files
authored
Merge pull request #373 from fsprojects/repo-assist/perf-chunkby-reuse-buffer-20260331-571b7516713643ae
[Repo Assist] perf: reuse ResizeArray buffer in chunkBy and chunkByAsync
2 parents 852f4b1 + 4ce009b commit 24c7791

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

release-notes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Release notes:
33

44
1.0.0
5+
- perf: TaskSeq.chunkBy and chunkByAsync reuse the ResizeArray buffer between chunks, reducing allocations on sequences with many chunk boundaries
56
- fixes: TaskSeq.insertAt, insertManyAt, removeAt, removeManyAt, updateAt now raise ArgumentNullException (not NullReferenceException) when given a null source; insertManyAt also validates the values argument
67
- refactor: simplify lengthBy and lengthBeforeMax to use while! and remove the redundant mutable 'go' and initial MoveNextAsync
78
- adds TaskSeq.distinctUntilChangedWith and TaskSeq.distinctUntilChangedWithAsync, #345

src/FSharp.Control.TaskSeq/TaskSeqInternal.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,7 @@ module internal TaskSeqInternal =
17541754
currentChunk.Add item
17551755
else
17561756
yield prevKey, currentChunk.ToArray()
1757-
currentChunk <- ResizeArray<'T>()
1757+
currentChunk.Clear() // reuse backing array; ToArray() already captured a snapshot
17581758
currentChunk.Add item
17591759
maybeCurrentKey <- ValueSome key
17601760

@@ -1782,7 +1782,7 @@ module internal TaskSeqInternal =
17821782
currentChunk.Add item
17831783
else
17841784
yield prevKey, currentChunk.ToArray()
1785-
currentChunk <- ResizeArray<'T>()
1785+
currentChunk.Clear() // reuse backing array; ToArray() already captured a snapshot
17861786
currentChunk.Add item
17871787
maybeCurrentKey <- ValueSome key
17881788

0 commit comments

Comments
 (0)