Skip to content

Commit c5ad247

Browse files
chore(size): ratchet For-bearing scenarios for the small-move fast path (rebased)
Re-measured on the rebased tree (next at 005a623, which already carries the #3322 and #3338 ratchets): hydrating 18.29 -> 18.34 KB, hydrating + stores 27.29 -> 27.34, CSR 13.70 -> 13.75, observe CSR 14.99 -> 15.04, observe + attribution 25.82 -> 25.87. ~600 B in every <For> scenario. Also: the engagement assertions read the dev-only __smallMoveHits counter, so they are skipped / gated under SIGNALS_TIER=prod; the oracle semantics still run on every tier. Co-authored-by: Cursor <[email protected]>
1 parent c8ae420 commit c5ad247

2 files changed

Lines changed: 37 additions & 13 deletions

File tree

‎packages/signals/tests/mapArray-smallmove.test.ts‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { describe, expect, it } from "vitest";
22
import { createRoot, createSignal, flush, mapArray, onCleanup } from "../src/index.js";
33
import { __smallMoveHits } from "../src/map.js";
44

5+
declare const __DEV__: boolean;
6+
57
/** SMALL-MOVE fast path: after prefix/suffix trimming, a same-or-shorter
68
* window whose mismatches are ≤32 displaced identities commits as in-place
79
* patches over sliced arrays — no window Map, no staging arrays.
@@ -82,7 +84,10 @@ function pair(initial: Item[]) {
8284
const items = (n: number): Item[] => Array.from({ length: n }, (_, i) => ({ id: i }));
8385
const hits = () => __smallMoveHits();
8486

85-
describe("mapArray small-move fast path — engagement", () => {
87+
// The counter only increments under __DEV__; on the prod tier
88+
// (`SIGNALS_TIER=prod`) engagement cannot be observed, so only the oracle
89+
// (semantics) suites below run there.
90+
describe.skipIf(!__DEV__)("mapArray small-move fast path — engagement", () => {
8691
it("engages for an arity-1 mapper on a >64 window and agrees with the general path", () => {
8792
const p = pair(items(200));
8893
const before = hits();
@@ -176,7 +181,7 @@ describe("mapArray small-move fast path — semantics vs the general path", () =
176181
);
177182
p.agree();
178183
}
179-
expect(hits()).toBeGreaterThan(before); // and it does engage for most of them
184+
if (__DEV__) expect(hits()).toBeGreaterThan(before); // and it does engage for most of them
180185
p.dispose();
181186
});
182187

@@ -187,7 +192,7 @@ describe("mapArray small-move fast path — semantics vs the general path", () =
187192
[next[1], next[998]] = [next[998], next[1]];
188193
const before = hits();
189194
p.set(next);
190-
expect(hits()).toBe(before + 1);
195+
if (__DEV__) expect(hits()).toBe(before + 1);
191196
p.agree();
192197
p.dispose();
193198
});
@@ -199,7 +204,7 @@ describe("mapArray small-move fast path — semantics vs the general path", () =
199204
const kept = src.filter((_, i) => i < 100 || i >= 105);
200205
const before = hits();
201206
p.set(rotateF(kept));
202-
expect(hits()).toBe(before + 1);
207+
if (__DEV__) expect(hits()).toBe(before + 1);
203208
p.agree();
204209
expect(p.disposed.fast.length).toBe(5);
205210
p.dispose();
@@ -210,7 +215,7 @@ describe("mapArray small-move fast path — semantics vs the general path", () =
210215
const src = p.oracle().map(m => m.item);
211216
const before = hits();
212217
p.set([...rotateF(src), { id: 9999 }]);
213-
expect(hits()).toBe(before);
218+
if (__DEV__) expect(hits()).toBe(before);
214219
p.agree();
215220
p.dispose();
216221
});
@@ -222,7 +227,7 @@ describe("mapArray small-move fast path — semantics vs the general path", () =
222227
next[100] = { id: 424242 };
223228
const before = hits();
224229
p.set(next);
225-
expect(hits()).toBe(before);
230+
if (__DEV__) expect(hits()).toBe(before);
226231
p.agree();
227232
expect(p.disposed.fast.length).toBe(1);
228233
p.dispose();
@@ -232,7 +237,7 @@ describe("mapArray small-move fast path — semantics vs the general path", () =
232237
const p = pair(items(1000));
233238
const before = hits();
234239
p.set(items(1000)); // all new objects
235-
expect(hits()).toBe(before);
240+
if (__DEV__) expect(hits()).toBe(before);
236241
p.agree();
237242
expect(p.disposed.fast.length).toBe(1000);
238243
p.dispose();
@@ -251,7 +256,7 @@ describe("mapArray small-move fast path — duplicate identities", () => {
251256
const before = hits();
252257
p.set([B, A, C, A, ...rotateF(filler)]);
253258
// Declined: the general path pairs the two A occurrences in order.
254-
expect(hits()).toBe(before);
259+
if (__DEV__) expect(hits()).toBe(before);
255260
p.agree();
256261
p.dispose();
257262
});

‎scripts/size/.size-limit.js‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,13 @@ module.exports = [
559559
// console-only; ~20 B is hydrate() refusing the client-render fallback
560560
// at a document root (`nodeType === 9` -> report the preload failure and
561561
// stop). All diagnostic prose is dev-gated; prod ships terse strings.
562-
limit: "17.72 KB",
562+
//
563+
// mapArray SMALL-MOVE fast path (#3227, rebased 2026-09-10): 17.72 KB ->
564+
// 18.34 KB, measured at 18.29 on the rebased tree (+600 B over 17.69).
565+
// Scan + commit as two functions (a replace compiles only the scan)
566+
// plus a 65-compare pre-probe in updateKeyedMap; identity-keyed mode
567+
// only. Lands in every scenario that bundles <For>.
568+
limit: "18.34 KB",
563569
modifyEsbuildConfig
564570
},
565571
{
@@ -668,7 +674,10 @@ module.exports = [
668674
// measured at 26.558. Core scheduler cost; see the core-floor note.
669675
// deep()/identity over chained views (#3323, 2026-09-09): 26.60 KB -> 26.70 KB,
670676
// measured at 26.648. Store cost; see the createStore note.
671-
limit: "26.70 KB",
677+
// mapArray SMALL-MOVE fast path (#3227, rebased 2026-09-10): 26.70 KB ->
678+
// 27.34 KB, measured at 27.29 on the rebased tree (+600 B over 26.69).
679+
// See the hydrating (no stores) note; same cost, every <For> scenario.
680+
limit: "27.34 KB",
672681
modifyEsbuildConfig
673682
},
674683
{
@@ -718,7 +727,10 @@ module.exports = [
718727
// measured at 13.00. Core scheduler cost; see the core-floor note.
719728
// Effect ownership on finalize re-entry (#3319, 2026-09-09): 13.04 KB -> 13.08 KB,
720729
// measured at 13.048. Core scheduler cost; see the core-floor note.
721-
limit: "13.08 KB",
730+
// mapArray SMALL-MOVE fast path (#3227, rebased 2026-09-10): 13.08 KB ->
731+
// 13.75 KB, measured at 13.70 on the rebased tree (+630 B over 13.07).
732+
// See the hydrating (no stores) note; same cost, every <For> scenario.
733+
limit: "13.75 KB",
722734
modifyEsbuildConfig
723735
},
724736
{
@@ -752,7 +764,10 @@ module.exports = [
752764
// router-agnostic navigation seam, a twin of withInteraction) and the
753765
// `flushEnd` hook site after flush()'s drain loop. Observe-only: prod
754766
// folds both out.
755-
limit: "14.44 KB",
767+
// mapArray SMALL-MOVE fast path (#3227, rebased 2026-09-10): 14.44 KB ->
768+
// 15.04 KB, measured at 14.99 on the rebased tree (+610 B over 14.38).
769+
// See the hydrating (no stores) note; same cost, every <For> scenario.
770+
limit: "15.04 KB",
756771
modifyEsbuildConfig: observeEsbuildConfig
757772
},
758773
{
@@ -793,7 +808,11 @@ module.exports = [
793808
// change as the hydrating scenario, compressing worse on the observe
794809
// tier's layout; the observe CSR scenario above did not move. Nothing
795810
// engine-side changed.
796-
limit: "25.26 KB",
811+
//
812+
// mapArray SMALL-MOVE fast path (#3227, rebased 2026-09-10): 25.26 KB ->
813+
// 25.87 KB, measured at 25.82 on the rebased tree (+600 B over 25.22).
814+
// See the hydrating (no stores) note; same cost, every <For> scenario.
815+
limit: "25.87 KB",
797816
modifyEsbuildConfig: observeEsbuildConfig
798817
},
799818
{

0 commit comments

Comments
 (0)