Uh oh!
There was an error while loading. Please reload this page.
[Repo Assist] perf: optimize windowed ring-buffer and toResizeArrayAsync - #351
[Repo Assist] perf: optimize windowed ring-buffer and toResizeArrayAsync#351github-actions[bot] wants to merge 3 commits into
Conversation
- windowed: replace integer modulo (count % windowSize) in the hot loop with explicit circular-buffer pointer arithmetic (increment + reset at boundary). Modulo is typically 5-10x slower than a conditional increment on modern CPUs. A separate 'writePos' mutable tracks the next write slot, and also serves directly as the 'start' index for the output blit, removing the second modulo that was needed before. - toResizeArrayAsync: rewrite from 'iter (SimpleAction (fun item -> res.Add item))' to a direct 'while! e.MoveNextAsync() do res.Add e.Current' loop. The old form allocated a closure that captured 'res', wrapped it in a struct-DU case, and dispatched through a pattern match inside 'iter'. The new form has no extra allocation and no indirection. All 5013 existing tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dsyme
commented
Mar 18, 2026
/repo-assist please update AGENTS.md to make ti very, very clear that, for suggested performance improvements, before/after benchmarking MUST be done to PROVE the performance improvement is real. Also do this benchmarking for this change. If the changes are not significant, remove the existing code changes and just include the AGENTS.md changes. |
dsyme
commented
Mar 18, 2026
/repo-assist please update AGENTS.md to make ti very, very clear that, for suggested performance improvements, before/after benchmarking MUST be done to PROVE the performance improvement is real. Also do this benchmarking for this change. If the changes are not significant, remove the existing code changes and just include the AGENTS.md changes. |
🤖 This is an automated pull request from Repo Assist.
Summary
Two focused performance improvements to hot-path internal functions.
1.
windowed— replace integer modulo with circular-buffer pointer arithmeticThe old implementation computed
count % windowSizetwice per element in the inner loop:Integer division/modulo is typically 5–10× slower than a simple increment + equality check on modern CPUs. The new implementation tracks the write position explicitly:
This also removes the need to compute
startseparately for the blit step.2.
toResizeArrayAsync— direct loop instead ofiter (SimpleAction(...))The old implementation:
This allocates a closure capturing
res, wraps it in a struct-DU case, and dispatches through a pattern-match insideiter. The new implementation:No closure allocation, no DU dispatch, one fewer level of task composition.
toResizeArrayAsyncis called by everytoArrayAsync,toListAsync, andtoSeqAsyncoperation, making this a broadly beneficial change.Test Status
Build: ✅ succeeded (0 warnings, 0 errors)
Tests: ✅ 5013 passed, 2 skipped (infrastructure), 0 failed
Branch:
repo-assist/perf-windowed-toarray-20260317