Commit 95e7838
perf: optimize windowed ring-buffer and toResizeArrayAsync
- 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>1 parent 6fd41af commit 95e7838
File tree
2 files changed
+21
-8
lines changed- src/FSharp.Control.TaskSeq
2 files changed
+21
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
546 | 546 | | |
547 | 547 | | |
548 | 548 | | |
549 | | - | |
| 549 | + | |
550 | 550 | | |
551 | 551 | | |
552 | 552 | | |
553 | 553 | | |
554 | | - | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
555 | 559 | | |
556 | 560 | | |
557 | 561 | | |
| |||
1804 | 1808 | | |
1805 | 1809 | | |
1806 | 1810 | | |
1807 | | - | |
| 1811 | + | |
| 1812 | + | |
1808 | 1813 | | |
1809 | 1814 | | |
| 1815 | + | |
1810 | 1816 | | |
1811 | 1817 | | |
1812 | | - | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
1813 | 1824 | | |
1814 | 1825 | | |
1815 | 1826 | | |
1816 | 1827 | | |
| 1828 | + | |
1817 | 1829 | | |
1818 | | - | |
1819 | 1830 | | |
1820 | | - | |
| 1831 | + | |
1821 | 1832 | | |
1822 | 1833 | | |
1823 | | - | |
1824 | | - | |
| 1834 | + | |
| 1835 | + | |
1825 | 1836 | | |
1826 | 1837 | | |
1827 | 1838 | | |
0 commit comments