Skip to content

Commit 2d2a190

Browse files
ryansolidClaude via Cursorcursoragent
committed
bench(signals): amortize projection-root-write over 20 commits per body
Three benchmarks share one process and one set of 20k-key fixtures, and each body performed a single commit. V8 emits a one-off ~100k-instruction tier-up chunk that attaches to whichever frame is running when it fires and lands in exactly one of the three windows — at ~540k Ir per root write that is 16-20% of a window, and it moves between windows on unrelated changes. CodSpeed's bisection of #3431 (2026-09-14) made this exact: a change costing ~300 instructions on its own path read as -8.9% on the root write and x2.4 on the untouched nested write; a provably no-op extra call added to `next` read as -5.5% on the root write and +22% on the untouched store setter (537,655 → 508,044 and 513,411 → 627,428 Ir; every reactive-graph symbol bit-identical). Each body now runs COMMITS = 20 commits. The chunk amortizes to <1% of a window — below the 5% gate — and the three stay per-commit comparable, which is the parity this file guards (#3352 derive vs #3044 setter floor). Absolute numbers re-baseline ×20. Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent c3ae310 commit 2d2a190

1 file changed

Lines changed: 29 additions & 10 deletions

File tree

‎packages/signals/tests/store/projection-root-write.bench.ts‎

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,23 @@
66
// #3044 prototype overlay. Guard the parity: the projection derive and the
77
// store setter should sit at the same per-commit floor, and the nested
88
// write (a small target — always cheap) is the reference.
9+
//
10+
// Each body runs COMMITS commits, not one. Three benchmarks share this
11+
// process and one set of 20k-key fixtures, and V8 emits a one-off ~100k
12+
// instruction tier-up chunk that attaches to whichever frame is running when
13+
// it fires — landing in exactly one of the three windows. At one commit per
14+
// body (~540k Ir for the root write) that is ~16-20% of a window, and it
15+
// moves between windows on unrelated changes: #3431 (a ~300-instruction
16+
// change on its own path) read as -8.9% here and x2.4 on the untouched
17+
// nested write, and a provably no-op extra call on `next` read as -5.5% here
18+
// and +22% on the untouched store setter (CodSpeed bisection, 2026-09-14).
19+
// Amortized over COMMITS the chunk is noise below the 5% gate; the numbers
20+
// stay per-commit-comparable across the three (all scale together).
921
import { bench, describe } from "vitest";
1022
import { createProjection, createRoot, createSignal, createStore, flush } from "../../src/index.js";
1123

1224
const KEYS = 20_000;
25+
const COMMITS = 20;
1326
const seed = () => Object.fromEntries(Array.from({ length: KEYS }, (_, i) => [`k${i}`, { n: i }]));
1427

1528
describe(`one root key per commit, ${KEYS}-key record`, () => {
@@ -58,21 +71,27 @@ describe(`one root key per commit, ${KEYS}-key record`, () => {
5871
});
5972

6073
bench("projection derive: delete + set one ROOT key (#3352)", () => {
61-
bump(++tick);
62-
flush();
74+
for (let c = 0; c < COMMITS; c++) {
75+
bump(++tick);
76+
flush();
77+
}
6378
});
6479

6580
bench("projection derive: write one NESTED field (reference)", () => {
66-
bumpNested(++tick);
67-
flush();
81+
for (let c = 0; c < COMMITS; c++) {
82+
bumpNested(++tick);
83+
flush();
84+
}
6885
});
6986

7087
bench("createStore setter: delete + set one root key (#3044 overlay)", () => {
71-
const i = ++tick % KEYS;
72-
setStore(d => {
73-
delete d[`k${i}`];
74-
d[`k${i}`] = { n: -i };
75-
});
76-
flush();
88+
for (let c = 0; c < COMMITS; c++) {
89+
const i = ++tick % KEYS;
90+
setStore(d => {
91+
delete d[`k${i}`];
92+
d[`k${i}`] = { n: -i };
93+
});
94+
flush();
95+
}
7796
});
7897
});

0 commit comments

Comments
 (0)