Skip to content

Commit 721eb06

Browse files
ryansolidclaudecursoragent
authored
fix(signals,web): dev cost checks judge only what the user can act on (#3739) (#3850)
* fix(signals,web): dev cost checks judge only what the user can act on (#3739) Performance tracks take a records-only hold (checks: false unless asked), WIDE_SCOPE_DEPS skips HMR plumbing sources and the insert's child-resolution pass (internal dev-only _wide / CONFIG_WIDE), engine-side HUGE_FAN_OUT skips plumbing subscribers, and the wideDeps default rises 30 -> 500. HUGE_FAN_IN keeps no exceptions. Co-authored-by: Claude <[email protected]> Co-authored-by: Cursor <[email protected]> * fix(signals): wideDeps default 200; document vite-plugin tracks and opt-in cost checks (#3739) Co-authored-by: Claude <[email protected]> Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Claude <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 09eadfe commit 721eb06

13 files changed

Lines changed: 479 additions & 41 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/signals": patch
3+
---
4+
5+
Attribution cost checks judge only what the scope's author can act on (#3739). `WIDE_SCOPE_DEPS` no longer counts HMR plumbing sources (the `solid-js/refresh` memo per component instance), skips framework scopes marked with the new internal dev-only `_wide` option (`CONFIG_WIDE`; not public API), and its `wideDeps` default rises from 30 to 200. The engine-side `HUGE_FAN_OUT` (`fanOut`) no longer counts plumbing subscribers. The always-on `HUGE_FAN_IN` and core `HUGE_FAN_OUT` (2000) keep no exceptions.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/web": patch
3+
---
4+
5+
Performance tracks no longer run the attribution cost checks by default (#3739). `enablePerformanceTracks()` — which `@solidjs/vite-plugin` calls in every `vite dev` session — now takes a records-only engine hold, so the six cost checks (`hotRuns`, `hotTime`, `wideDeps`, `unstableMemos`, `fanOut`, `wastedRecompute`) are opt-in again. To turn them back on, pass `enablePerformanceTracks({ attribution: { checks: true } })` (or `performanceTracks: { attribution: { checks: true } }` in the vite plugin), or take your own `attribution.enable()` hold. In dev builds, the `insert` child-resolution effect (which must track each row's resolved child, e.g. every `<Show>` row of a `<For>`) is also exempt from `WIDE_SCOPE_DEPS`; `HUGE_FAN_IN` still covers it.

‎documentation/solid-2.0/08-dev-diagnostics.md‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ One code, one threshold story, two reporters. **Always on** wherever the diagnos
424424

425425
One recompute pass tracked an unusually large number of distinct sources (same thresholds as `HUGE_FAN_OUT`; the sources the pass actually tracked, counted once at the end of the pass — repeat reads of the same source excluded). This is the coarse-read signature — e.g. a helper that touches a whole store, or one memo derived from everything. Narrow the read or split the derivation so each computation tracks only what it needs.
426426

427-
Related: `WIDE_SCOPE_DEPS` (below) fires at a much lower threshold, but only while the attribution engine is enabled — it names the offending sources. `HUGE_FAN_IN` is the always-on backstop for the pathological case.
427+
Related: `WIDE_SCOPE_DEPS` (below) fires at a lower threshold, but only while the attribution engine runs its cost checks — it names the offending sources. `HUGE_FAN_IN` is the always-on backstop for the pathological case, and it has no exemptions: the renderer's insert child-resolution pass and HMR plumbing, which `WIDE_SCOPE_DEPS` does not judge, still count here.
428428

429429
#### `GRAPH_GROWTH`
430430

@@ -442,7 +442,7 @@ Perf-kind warnings emitted by the **attribution engine** — they only fire whil
442442

443443
- `HOT_SCOPE_RERUNS`: one scope re-ran 120+ times within 1000ms (above animation-frame cadence, so a legitimate rAF-driven scope doesn't cry wolf). The message names the most recent cause chain. When many scopes go hot from the _same_ root cause (a selection write re-running every row), only the first warns per-node; the rest fold into `HOT_SCOPE_FANOUT` (below) so one culprit can't bury the console in victim warnings.
444444
- `HOT_SCOPE_TIME`: one scope's summed self-time exceeded 8ms within 1000ms — half a frame in one scope. Catches the few-but-expensive runs that counts miss.
445-
- `WIDE_SCOPE_DEPS`: a scope's dependency count reached 30 (re-warns after another 50% growth), with the source names listed.
445+
- `WIDE_SCOPE_DEPS`: a scope's dependency count reached 200 (re-warns after another 50% growth), with the source names listed. It counts what the scope's author can act on: HMR plumbing sources (the dev-only `solid-js/refresh` memo per component instance) are not counted, and in dev builds the renderer's insert child-resolution pass — the effect that must track each row's resolved child, e.g. every `<Show>` row of a `<For>` — is not judged. A memo combining hundreds of per-row memos is judged as written.
446446

447447
All three thresholds are configurable (or disable-able) through `enable()` options.
448448

@@ -956,7 +956,7 @@ The runtime derives a request's trace itself in every tier — the W3C `tracepar
956956
| `HOT_SCOPE_RERUNS` | warn | perf | 120+ re-runs of one scope in 1s (attribution enabled) |
957957
| `HOT_SCOPE_FANOUT` | warn | perf | 5+/50+/500+ scopes hot from one root cause (attribution enabled) |
958958
| `HOT_SCOPE_TIME` | warn | perf | 8ms+ self-time in one scope in 1s (attribution enabled) |
959-
| `WIDE_SCOPE_DEPS` | warn | perf | Scope subscribed to 30+ sources (attribution enabled) |
959+
| `WIDE_SCOPE_DEPS` | warn | perf | Scope subscribed to 200+ sources (attribution cost checks on) |
960960
| `ASYNC_WATERFALL` | info/warn | perf | 2+/3+ sequential async flights, origin-proven (attribution enabled) |
961961
| `UNSTABLE_MEMO_OUTPUT` | warn | perf | Memo returned a new-but-equivalent container 4+ runs running (attribution enabled) |
962962
| `WASTED_RECOMPUTE` | warn | perf | 80%+ of a scope's 5+ runs in a second produced an unchanged value for 2ms+ of compute — inputs change, result does not (attribution enabled) |
@@ -1014,7 +1014,7 @@ const release = attribution.enable({
10141014
historyLimit: 200, // ring buffer size
10151015
hotRuns: { count: 120, windowMs: 1000 }, // or false
10161016
hotTime: { budgetMs: 8, windowMs: 1000 }, // or false
1017-
wideDeps: 30, // or false
1017+
wideDeps: 200, // or false
10181018
unstableMemos: 4, // or false
10191019
fanOut: 250, // or false (HUGE_FAN_OUT threshold while enabled)
10201020
waterfalls: { minFlightMs: 50 }, // or false
@@ -1209,10 +1209,12 @@ import { enablePerformanceTracks } from "@solidjs/web/performance-tracks";
12091209
const disable = enablePerformanceTracks({
12101210
minMs: 0, // floor for run spans; 0 in dev, 0.05 in observe builds
12111211
rich: true, // performance.measure with tooltips/properties (dev default) vs console.timeStamp
1212-
attribution: { values: "labels" } // options for the engine hold it takes (log: false; values: the tier's default)
1212+
attribution: { values: "labels" } // options for the engine hold it takes (log: false, checks: false; values: the tier's default)
12131213
});
12141214
```
12151215
1216+
**`vite-plugin-solid` enables the tracks for you under `vite dev`** (`@solidjs/vite-plugin` 3.0.0-next.46+): its `performanceTracks` option defaults to on while serving, injects a client module that calls `enablePerformanceTracks()` ahead of the app's entry, and is off in `vite build`, preview and vitest. Pass `performanceTracks: false` to turn it off, or an object, which is passed through as the `enablePerformanceTracks()` options (`{ minMs, rich, attribution }`). The tracks' engine hold is **records only**: it runs none of the six cost checks (`hotRuns`, `hotTime`, `wideDeps`, `unstableMemos`, `fanOut`, `wastedRecompute`), so a default dev session paints the timeline without turning them on. To get them, opt in explicitly — `enablePerformanceTracks({ attribution: { checks: true } })`, `performanceTracks: { attribution: { checks: true } }` in the plugin, or a hold of your own (`attribution.enable()`), which turns them on beside the tracks while it is held.
1217+
12161218
The adapter scrubs nothing itself: what the spans and tooltips say about values and elements is what the engine put on the records under the hold's `values` level (above) — the tier's default unless the `attribution` option names one: dev shows previews and element text (`"full"`), an observe build shows neither (`"none"`); pass `attribution: { values: "labels" }` for the control labels in an observe build, or `"none"` for a dev timeline without user data.
12171219
12181220
Group `Solid`, tracks in order: **Interactions** — the input delay, the handler, then the settle to `committed`/`held` (a silent hold as a warning); **Propagation** — one span per scheduler drain labelled by the writes that started it and what they reached (`count 0 → 1 — click on button#next · 5 runs, 1 unchanged`), with every run inside it beneath, labelled by what made it run (`<TodoRow> › effect ← doubled`) — the write's path through the graph as a flame; **Effects** and **Memos** — one span per re-run, creation run (`· create`) and effect callback (`· callback`), coloured by self time, `warning` for a run that changed nothing; **Async** — flights kickoff → landing (abandoned ones as warnings) and fallbacks shown → hidden; **Holds** — each wait labelled by its blockers, `warning` when silent, `error` when long; **Navigations** — request → settle by route pattern; **Server** — server-function calls and frame streams. Every span is emitted retroactively from the record's own `performance.now()` stamps — nothing brackets a hot path.
@@ -1221,7 +1223,7 @@ The **Server** track also shows the server's side of the work it painted from th
12211223
12221224
Labels read as source: a flow control's own nodes fold into its tag (`<App> › <Show>` rather than `<App> › <Show> › condition value`) and a composed primitive's nodes into the primitive (`createDebounced.value` → `createDebounced`, the same rule as `store.user`), with the runtime's name kept in the span's `Node` property; the `Owner path` property is the unfolded truth and `Node id` the engine's id. A label also starts at the nearest component the developer wrote — `<Search> › results`, not `<Document> › body › <App> › <Router> › … › <Search> › results` — because a track entry is only as wide as its span and the panel elides the middle of a label that does not fit, which in a full path is exactly the part that says which component this is. Solid's own flow controls (`<Show>`, `<For>`, `<Loading>`, `<Portal>`…) are not anchors: a node under `<Card> › <Show>` labels `<Card> › <Show> › effect`. The same cut applies to fallback spans, flights, findings and the Server track's boundary spans; wherever the label is shorter than the path, the full path is the `Owner path` property. Rich mode carries the why-chain (`formatRerun`) as the tooltip, and causes, deps added/removed, phase, origin and interaction as properties.
12231225
1224-
Findings become markers: every `DiagnosticEvent` delivered while enabled is a marker on the panel's Timings track (`SILENT_HOLD — <Search>`), coloured by severity, and — at `warn` or worse — annotated as a performance issue for the Insights sidebar (`detail.devtools.performanceIssue`, with the repair guide's section for the code as its link; Chrome ignores the annotation where it is not yet supported). In dev, every span and marker is emitted inside the `console.createTask` task of the component it belongs to, so the entry's stack in the panel points at the JSX site that rendered the component rather than at the engine. The dev component wrapper creates that task only for components rendered while an attribution engine is installed — `console.createTask` captures a stack per call, roughly the wrapper's own cost again and ~90 B retained per instance, DevTools open or not, and only an attribution consumer reads it — so a dev session with nothing enabled pays nothing, and the tracks enabled at bootstrap see every component's site (a component rendered before any consumer enabled carries no task and its spans are emitted plainly). Enabling takes its own hold on the engine (`attribution.enable({ log: false, ... })` — asking for no console log, which quiets the console only while no other holder wants it), so it coexists with a diagnostics capture or an APM adapter; the returned function releases it. There is one instance per page: a second `enablePerformanceTracks()` while one is running joins it (the first call's options stand) and returns its own release, and the instance is torn down when every release has been called — a module HMR re-evaluates lands back on one set of tracks, not two painters. The adapter is the one place host APIs are called from inside the engine's hooks, and it guards them: a `performance`/`console` call that throws drops that entry (dev warns once) and never reaches the engine.
1226+
Findings become markers: every `DiagnosticEvent` delivered while enabled is a marker on the panel's Timings track (`SILENT_HOLD — <Search>`), coloured by severity, and — at `warn` or worse — annotated as a performance issue for the Insights sidebar (`detail.devtools.performanceIssue`, with the repair guide's section for the code as its link; Chrome ignores the annotation where it is not yet supported). In dev, every span and marker is emitted inside the `console.createTask` task of the component it belongs to, so the entry's stack in the panel points at the JSX site that rendered the component rather than at the engine. The dev component wrapper creates that task only for components rendered while an attribution engine is installed — `console.createTask` captures a stack per call, roughly the wrapper's own cost again and ~90 B retained per instance, DevTools open or not, and only an attribution consumer reads it — so a dev session with nothing enabled pays nothing, and the tracks enabled at bootstrap see every component's site (a component rendered before any consumer enabled carries no task and its spans are emitted plainly). Enabling takes its own hold on the engine (`attribution.enable({ log: false, checks: false, ... })` — asking for no console log and records only, which quiets the console and the six cost checks only while no other holder wants them; pass `attribution: { checks: true }` to have the tracks' hold run the checks, their findings painted as markers), so it coexists with a diagnostics capture or an APM adapter; the returned function releases it. There is one instance per page: a second `enablePerformanceTracks()` while one is running joins it (the first call's options stand) and returns its own release, and the instance is torn down when every release has been called — a module HMR re-evaluates lands back on one set of tracks, not two painters. The adapter is the one place host APIs are called from inside the engine's hooks, and it guards them: a `performance`/`console` call that throws drops that entry (dev warns once) and never reaches the engine.
12251227
12261228
### Architecture
12271229

‎packages/signals/src/core/attribution.ts‎

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
CONFIG_GUESS,
1010
CONFIG_OVERRIDE,
1111
CONFIG_PLUMBING,
12+
CONFIG_WIDE,
1213
CONFIG_VERDICT,
1314
NOT_PENDING
1415
} from "./constants.js";
@@ -440,8 +441,11 @@ export interface AttributionOptions {
440441
hotRuns?: { count: number; windowMs: number } | false;
441442
/**
442443
* Wide-scope warning: emit a diagnostic when a scope's dependency count
443-
* reaches this (default 30) — the coarse-read / helper-leak signature.
444-
* Re-warns only if the count then grows by another 50%. `false` disables.
444+
* reaches this (default 200) — the coarse-read / helper-leak signature.
445+
* Re-warns only if the count then grows by another 50%. HMR plumbing is
446+
* not counted, and in dev builds the renderer's insert child-resolution
447+
* pass (which must track every row's resolved child) is not judged;
448+
* HUGE_FAN_IN (2000, always on) still covers both. `false` disables.
445449
*/
446450
wideDeps?: number | false;
447451
/**
@@ -479,8 +483,8 @@ export interface AttributionOptions {
479483
* same code the always-on core check emits from GRAPH_SIZE_WARN_AT (2000)
480484
* up, with `data.write` naming the invalidation; the engine hands over to
481485
* the core there, so one change never carries two findings. Once per
482-
* node, re-warning once the count has grown by another 500. `false`
483-
* leaves only the always-on threshold.
486+
* node, re-warning once the count has grown by another 500. HMR plumbing
487+
* subscribers are not counted. `false` leaves only the always-on threshold.
484488
*/
485489
fanOut?: number | false;
486490
/**
@@ -645,7 +649,7 @@ const defaultOptions = {
645649
stacks: false,
646650
historyLimit: 200,
647651
hotRuns: { count: 120, windowMs: 1000 } as { count: number; windowMs: number } | false,
648-
wideDeps: 30 as number | false,
652+
wideDeps: 200 as number | false,
649653
hotTime: { budgetMs: 8, windowMs: 1000 } as { budgetMs: number; windowMs: number } | false,
650654
unstableMemos: 4 as number | false,
651655
wastedRecompute: { minRuns: 5, ratio: 0.8, budgetMs: 2, windowMs: 1000 } as
@@ -1099,13 +1103,6 @@ export function formatOrigin(origin: ChangeOrigin): string {
10991103
}
11001104

11011105
/** Record a root change (setSignal / refresh / async landing) on the node. */
1102-
/** Live subscriber count, walked on demand — the core keeps no counter. */
1103-
function countSubscribers(node: Signal<any> | Computed<any>): number {
1104-
let n = 0;
1105-
for (let s = node._subs; s !== null; s = s._nextSub) n++;
1106-
return n;
1107-
}
1108-
11091106
/**
11101107
* HUGE_FAN_OUT from the engine's lower `fanOut` threshold (see dev.ts): a
11111108
* committed root invalidation reaching hundreds of subscribers re-runs all
@@ -1114,15 +1111,23 @@ function countSubscribers(node: Signal<any> | Computed<any>): number {
11141111
* was a post-construction field that forked node shapes). Stops at
11151112
* GRAPH_SIZE_WARN_AT, where the always-on core check takes over, so the two
11161113
* never fire for the same write; the once-per-node dedupe is the core's.
1114+
* HMR plumbing subscribers (the refresh memo of every mounted instance, on
1115+
* a component's registration signal) are not counted toward `fanOut`; the
1116+
* handover is on the full list, which is what the core counts.
11171117
*/
11181118
function checkFanOut(
11191119
node: Signal<any> | Computed<any>,
11201120
kind: Exclude<ChangeKind, "derived">
11211121
): void {
11221122
const limit = options.fanOut;
11231123
if (typeof limit !== "number") return;
1124-
const subs = countSubscribers(node);
1125-
if (subs < limit || subs >= GRAPH_SIZE_WARN_AT) return;
1124+
let all = 0;
1125+
let subs = 0;
1126+
for (let s = node._subs; s !== null; s = s._nextSub) {
1127+
all++;
1128+
if (!(s._sub._config & CONFIG_PLUMBING)) subs++;
1129+
}
1130+
if (subs < limit || all >= GRAPH_SIZE_WARN_AT) return;
11261131
noteFanOut(node, subs, kind);
11271132
}
11281133

@@ -1212,18 +1217,25 @@ function captureDeps(el: Computed<any>): unknown[] {
12121217

12131218
/**
12141219
* Wide-scope warning — the coarse-read / helper-leak signature: one scope
1215-
* subscribed to dozens of sources re-runs when ANY of them change. Fired from
1220+
* subscribed to hundreds of sources re-runs when ANY of them change. Fired from
12161221
* recordRerun for re-runs and directly from recompute for creation runs (a
1217-
* memo can be born too wide). Re-warns only on 50% further growth.
1222+
* memo can be born too wide). Re-warns only on 50% further growth. Counts
1223+
* what the scope's author can act on: HMR plumbing sources are not counted,
1224+
* and a framework scope wide by construction (CONFIG_WIDE) is not judged —
1225+
* the always-on HUGE_FAN_IN still is.
12181226
*/
12191227
function checkDepWidth(el: Computed<any>): void {
12201228
const limit = options.wideDeps;
1221-
if (limit === false) return;
1229+
// Only dev sets CONFIG_WIDE (see constants.ts).
1230+
if (limit === false || (__DEV__ && el._config & CONFIG_WIDE)) return;
12221231
let count = 0;
12231232
const names: string[] = [];
12241233
for (let l = el._deps; l !== null; l = l._nextDep) {
1225-
count++;
1226-
if (names.length < 12) names.push(nodeName(l._dep));
1234+
// HMR plumbing is a dev-only hop the scope cannot read past: not a source.
1235+
if (!(l._dep._config & CONFIG_PLUMBING)) {
1236+
count++;
1237+
if (names.length < 12) names.push(nodeName(l._dep));
1238+
}
12271239
if (l === el._depsTail) break; // the validated prefix, as captureDeps
12281240
}
12291241
const node = el as AttributedNode;

0 commit comments

Comments
 (0)