[Repo Assist] Perf/code: replace ref cells with mutable in ~30 API functions#295
Draft
github-actions[bot] wants to merge 2 commits intomainfrom
Draft
Conversation
Modernises ~30 public API functions to use 'mutable' local variables instead of heap-allocated 'ref' cells (! and := operators). This reduces GC pressure in hot paths and aligns the code with idiomatic modern F#. Affected functions: tryLast, tryFirst, tryItem, compareWithAsync, reduceAsync, scanAsync, pairwise, windowed, pickAsync, tryPickAsync, tryFindIndex, tryFindIndexAsync, threadStateAsync, zipWithAsync, zipWithAsyncParallel, zipWithAsync3, allPairs, takeWhileAsync, takeUntilSignal, skipWhileAsync, skipWhileInclusiveAsync, skipUntilSignal, tryTail, splitAt, toArrayAsync, concatSeq, interleaveChoice, chunkBySize, chunkByAsync, mergeChoiceEnum, distinctUntilChangedWithAsync, emitEnumerator, removeAt, updateAt, insertAt, ofObservableBuffered, Disposables.Dispose. All 372 tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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 PR was created by Repo Assist, an automated AI assistant.
Modernises ~30 public API functions to use
mutablelocal variables instead of heap-allocatedrefcells (!/:=operators). This has two benefits:Performance (Task 8):
refcells are heap-allocated objects — everylet x = ref vallocates a newRef<'T>on the heap. Replacing them withmutablelocals eliminates these allocations in frequently-called hot paths (e.g.toArrayAsync,tryLast,zip*,skip*,take*,scan*), reducing GC pressure.Code clarity (Task 5): The
ref/!/:=style is a legacy pattern from early F#. Modern F# usesmutable/<-which is more readable and consistent with the rest of the codebase (many optimised enumerators already uselet mutable).Affected functions
tryLast,tryFirst,tryItem,compareWithAsync,reduceAsync,scanAsync,pairwise,windowed,pickAsync,tryPickAsync,tryFindIndex,tryFindIndexAsync,threadStateAsync,zipWithAsync,zipWithAsyncParallel,zipWithAsync3,allPairs,takeWhileAsync,takeUntilSignal,skipWhileAsync,skipWhileInclusiveAsync,skipUntilSignal,tryTail,splitAt,toArrayAsync,concatSeq,interleaveChoice,chunkBySize,chunkByAsync,mergeChoiceEnum,distinctUntilChangedWithAsync,emitEnumerator,removeAt,updateAt,insertAt,ofObservableBuffered,Disposables.DisposeNote: infrastructure object-expression code (e.g.
tryWith,tryFinally,collectSeq) that captures state across multiple method calls still usesref— that is correct and intentional, asmutablecannot be captured across closure boundaries.Changes
src/FSharp.Control.AsyncSeq/AsyncSeq.fs— ~30 functions modernisedRELEASE_NOTES.md— 4.11.0 entry updatedTest Status
✅ Build succeeded (0 errors, pre-existing FS9999 warning only for
groupByAsync).✅ All 372 tests pass.