Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lanes-guess-layer-split.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/signals": patch
---

The lane engine is split along the guess boundary: `lanes.ts` keeps the sub-hold core every lane needs (the lane record, link / blocked / reveal / landing, the lane read and a lane pass's tail — what `isPending()` and `latest()` install for their verdict lanes), and the new `guesses.ts` carries what only a written guess reaches (`createOptimistic` / `createOptimisticStore`: `optimisticWrite`, the seam's `applyGuesses`, `take`, `supersede`, `laneCorrections`, `laneOutcome`, a write landing on a guess, a revert landing's give-back), installed behind hooks when imported. Pay-for-use (#2883): an app using `isPending`/`latest` without optimism no longer ships the guess layer (−531 B brotli on `+ isPending/latest`, −454 to −533 B on the live pages); an app with both pays the indirection (+15 B brotli). No rule or screen changes.
29 changes: 29 additions & 0 deletions packages/signals/docs/INTERNALS-ASYNC-STATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,35 @@ The findings that used to follow here (§5a–§5h, 2026-07-06 → 2026-07-16) a

## 7. Decision log

- 2026-11-10: **The lane engine split along the guess boundary** (the
§8.6 split, b3926358b, ported onto today's `lanes.ts`; a module boundary,
no rule). `lanes.ts` keeps the sub-hold core every lane needs — the lane
record (`newLane`, `verdictLane`), link / blocked / reveal / landing
(`linkLanes`, `laneSeam`, `laneSeams`, `endLanes`, `dissolveLane`,
`lanesBlocked`, `heldMountUnder`, `laneWait`), the lane read and a lane
pass's tail (`laneRead`, `enterLane`, `laneStage`), `laneWrite`'s
derivation arm, `adoptParked`, `laneServed` — installed by verdict.ts's
verdict lanes as before. The new `guesses.ts` carries what only a written
guess reaches: `optimisticWrite` and the unflushed guesses, the seam's
`applyGuesses`, `take` and the `kept` give-back, `supersede` and the
correction round (`laneCorrections`), `laneOutcome` with the provenance
test (`stale`, `answered`), a write landing on a guess (`guessWrite`,
`laneWrite`'s old guess arm) and a revert landing's give-back
(`revertLanding`, `endLanes`' old `kept` loop). The core reaches them
through `installGuessLayer` (lanes.ts: `take`, `guessWrite`,
`revertLanding`, each site behind CONFIG_GUESS or `guessed`) and
`installGuessHooks` (scheduler.ts: `laneOutcome`, `applyGuessesAt`,
`laneCorrections`, every site null-tolerant); `guessed` stays the core's
flag, armed by the layer (`armGuessed`) so a bundle without it folds the
arms, and `markJudged` is the core's side of `applyGuessesAt`. `marked`,
`inFlight`, `guessFlights`, `rerun`, `landBeneath` stay in the core
(`dissolveLane`, `lanesBlocked`, `laneSeams` read them with no guess
written). Measured (scripts/size, next @ 083a0bd78): `+ isPending/latest`
−531 B brotli / −1,551 B minified, the three live pages −454 to −533 B,
every floor and plain-store scenario 0 B, `hydrating + every store
primitive family` (both halves) +15 B brotli / +157 B minified. Suites,
the seat shadow and 50k × 3 seeds against `next`'s recording: no screen
moves (documentation/plans/reader-seat-rebuild.md §9.3).
- 2026-11-09: **A store guess is one node — the guess carrier** (S2's
shape, ported onto `next` without S1's staging; D-33's point-of-write
clause, S-59, #4724). Before, an optimistic setter was scattered into the
Expand Down
16 changes: 8 additions & 8 deletions packages/signals/docs/RULES-INDEX.md

Large diffs are not rendered by default.

378 changes: 378 additions & 0 deletions packages/signals/src/core/guesses.ts

Large diffs are not rendered by default.

385 changes: 53 additions & 332 deletions packages/signals/src/core/lanes.ts

Large diffs are not rendered by default.

22 changes: 15 additions & 7 deletions packages/signals/src/core/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export let laneAdoptHook: ((r: Computed<any>) => boolean) | null = null;
* committed value (lanes.ts `laneServed`). */
export let laneServedHook: ((c: Computed<any>, el: Signal<any> | Computed<any>) => void) | null =
null;
/** A guess was written (lanes.ts `optimisticWrite`): the arms only a guess
/** A guess was written (guesses.ts `optimisticWrite`): the arms only a guess
* reaches (CONFIG_GUESS) — a build without `createOptimistic` or
* `createOptimisticStore` never sets it, and its bundler folds them. */
export let guessing = false;
Expand All @@ -103,28 +103,36 @@ export function armGuessing(): void {
export function installLaneHooks(
read: NonNullable<typeof laneReadHook>,
stage: NonNullable<typeof laneStageHook>,
outcome: NonNullable<typeof laneOutcomeHook>,
write: NonNullable<typeof laneWriteHook>,
applyGuesses: NonNullable<typeof applyGuessesHook>,
seams: NonNullable<typeof laneSeamsHook>,
corrections: NonNullable<typeof laneCorrectionsHook>,
end: NonNullable<typeof endLanesHook>,
blocked: NonNullable<typeof lanesBlockedHook>,
adopt: NonNullable<typeof laneAdoptHook>,
served: NonNullable<typeof laneServedHook>
): void {
laneReadHook = read;
laneStageHook = stage;
laneOutcomeHook = outcome;
laneWriteHook = write;
applyGuessesHook = applyGuesses;
laneSeamsHook = seams;
laneCorrectionsHook = corrections;
endLanesHook = end;
lanesBlockedHook = blocked;
laneAdoptHook = adopt;
laneServedHook = served;
}
// The guess layer (guesses.ts; installed when `createOptimistic` or
// `createOptimisticStore` is imported): a written guess's own pass judged
// (`laneOutcome`, core.ts `recompute`), the seam's guesses opening their
// lanes (`applyGuessesAt`), the body-end corrections (`laneCorrections`).
// Null without it: every site tolerates it.
export function installGuessHooks(
outcome: NonNullable<typeof laneOutcomeHook>,
applyGuesses: NonNullable<typeof applyGuessesHook>,
corrections: NonNullable<typeof laneCorrectionsHook>
): void {
laneOutcomeHook = outcome;
applyGuessesHook = applyGuesses;
laneCorrectionsHook = corrections;
}
// Boundaries (boundaries.ts): the display consumers between an observer
// and the root. `catch` — status from a frame reader, nearest boundary
// first (true: caught, the root never hears of it; a clear — flags 0 —
Expand Down
2 changes: 1 addition & 1 deletion packages/signals/src/signals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
} from "./core/scheduler.js";
import { REACTIVE_JOINED, STATUS_ERROR, STATUS_PENDING } from "./core/constants.js";
import { unwrapStatusError } from "./core/error.js";
import { optimisticWrite } from "./core/lanes.js";
import { optimisticWrite } from "./core/guesses.js";
import { truthConfirmed, truthRead } from "./core/truth.js";

/**
Expand Down
10 changes: 2 additions & 8 deletions packages/signals/src/store/optimistic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,8 @@ import {
import { link } from "../core/graph.js";
import { getObserver } from "../core/owner.js";
import { devGuardOptimisticBeforeLoad } from "../core/dev.js";
import {
guessedValueOf,
latestOf,
optimisticWrite,
pendingGuessOf,
setLaneValue,
take
} from "../core/lanes.js";
import { latestOf, setLaneValue } from "../core/lanes.js";
import { guessedValueOf, optimisticWrite, pendingGuessOf, take } from "../core/guesses.js";
import { covered } from "../core/truth.js";
import {
clock,
Expand Down
18 changes: 16 additions & 2 deletions packages/signals/tests/treeshake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe("pay-for-use tree-shaking (#2883)", { timeout: 30_000 }, () => {
"deferred.ts",
"core/verdict.ts",
"core/lanes.ts",
"core/guesses.ts",
"core/action.ts",
"core/context.ts"
])
Expand Down Expand Up @@ -478,6 +479,7 @@ describe("pay-for-use tree-shaking (#2883)", { timeout: 30_000 }, () => {
retainedFrom(retained, [
"core/verdict.ts",
"core/lanes.ts",
"core/guesses.ts",
"affects.ts",
"boundaries.ts",
"map.ts"
Expand Down Expand Up @@ -510,7 +512,12 @@ describe("pay-for-use tree-shaking (#2883)", { timeout: 30_000 }, () => {
const { retained } = await bundleFixture(
`export { createSignal, createEffect, createRoot, flush, createOptimistic } from "sigsrc";`
);
expect(retainedFrom(retained, ["core/lanes.ts"])).toEqual(["core/lanes.ts"]);
// The lane engine and its guess layer (guesses.ts: the written guess —
// `optimisticWrite`, `applyGuesses`, `supersede`, `laneCorrections`).
expect(retainedFrom(retained, ["core/lanes.ts", "core/guesses.ts"])).toEqual([
"core/lanes.ts",
"core/guesses.ts"
]);
});

it("createDeferred loads the deferred module and the mark core, and nothing else new", async () => {
Expand All @@ -532,6 +539,7 @@ describe("pay-for-use tree-shaking (#2883)", { timeout: 30_000 }, () => {
"affects.ts",
"core/verdict.ts",
"core/lanes.ts",
"core/guesses.ts",
"core/action.ts"
])
).toEqual([]);
Expand Down Expand Up @@ -559,7 +567,12 @@ describe("pay-for-use tree-shaking (#2883)", { timeout: 30_000 }, () => {
// lanes, and if a future round decouples the verdict lane from the
// engine this expectation is the one to flip to an exclusion.
expect(retainedFrom(retained, ["core/lanes.ts"])).toEqual(["core/lanes.ts"]);
expect(retainedFrom(retained, ["store/", "boundaries.ts", "map.ts", "affects.ts"])).toEqual([]);
// Not the guess layer: a verdict lane is the core's, and nothing in a
// bundle without `createOptimistic` writes a guess (pay-for-use; the
// split measured -531 B brotli on `+ isPending/latest`, 2026-11-10).
expect(
retainedFrom(retained, ["core/guesses.ts", "store/", "boundaries.ts", "map.ts", "affects.ts"])
).toEqual([]);
});

// ---- dist-artifact assertions ----
Expand Down Expand Up @@ -637,6 +650,7 @@ describe("pay-for-use tree-shaking (#2883)", { timeout: 30_000 }, () => {
"affects.js",
"core/verdict.js",
"core/lanes.js",
"core/guesses.js",
"core/action.js",
"core/context.js"
])
Expand Down
4 changes: 2 additions & 2 deletions scripts/size/floor-caps.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"minified": 102212
},
"page: live server components (base + live/GET + action + isPending/latest)": {
"cap": "40.92 KB",
"minified": 123431
"cap": "40.43 KB",
"minified": 121949
},
"server: floor (getRequestEvent + isServer)": {
"cap": "1.29 KB",
Expand Down
Loading
Loading