Skip to content

[Repo Assist] Performance: replace ref cells with mutable in singleton, collectSeq, takeWhileInclusive, takeWhileInclusiveAsync#305

Merged
dsyme merged 2 commits intomainfrom
repo-assist/perf-mutable-ref-cells-modernize-36977289b3f4862a
Apr 7, 2026
Merged

[Repo Assist] Performance: replace ref cells with mutable in singleton, collectSeq, takeWhileInclusive, takeWhileInclusiveAsync#305
dsyme merged 2 commits intomainfrom
repo-assist/perf-mutable-ref-cells-modernize-36977289b3f4862a

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 7, 2026

🤖 This is an automated pull request from Repo Assist.

Summary

Modernises 4 remaining functions that still used old-style ref cells (! / := operators) to use mutable local variables instead. This eliminates heap-allocated Ref<T> objects in these enumerators, reducing GC pressure — consistent with the style improvements made across ~30 functions in v4.11.0.

Changes

Function Change
singleton let state = ref 0let mutable state = 0
collectSeq let state = ref (CollectSeqState.NotStarted inp)let mutable state = ...
takeWhileInclusive let fin = ref falselet mutable fin = false
takeWhileInclusiveAsync let fin = ref falselet mutable fin = false

Motivation

In .NET, ref cells are heap-allocated objects (FSharpRef<T>). Every time the enclosing function creates a new enumerator, a new heap object is allocated just to hold the state. Using mutable fields on the enumerator object itself (which is already heap-allocated) avoids this extra allocation and dereference overhead.

Test Status

All 402 tests pass (run locally with .NET 8 / dotnet test -c Release)

Passed!  - Failed: 0, Passed: 402, Skipped: 0, Total: 402

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@7ee2b60744abf71b985bead4599640f165edcd93

…ileInclusive, takeWhileInclusiveAsync

Modernises 4 remaining functions that still used old-style ref cells
(! / := operators) to use mutable local variables instead. This eliminates
heap-allocated Ref<T> objects in these enumerators, reducing GC pressure.

- singleton: state ref 0 -> mutable state = 0
- collectSeq: state ref (CollectSeqState...) -> mutable state
- takeWhileInclusive: fin ref false -> mutable fin = false
- takeWhileInclusiveAsync: fin ref false -> mutable fin = false

All 402 tests pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dsyme dsyme marked this pull request as ready for review April 7, 2026 17:05
@dsyme dsyme merged commit 84c410d into main Apr 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant