You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e10a4ba
Browse filesBrowse the repository at this point in the historyBrowse files
authored
perf(ssr): spread-element tails as markup, hoisted spread sources, ssrElement/merge at the writer floor (#3562)
* perf(ssr): spread elements — trailing attributes as markup, source literals hoisted, ssrElement/merge fast paths
Compilers (Babel + Oxc, byte-identical):
- Attributes after an element's last spread are markup, not a source.
`<li {...rest} class="row" data-id={id}>` compiles to
ssrElement("li", rest, …, _sk$, () => ' class="row"' + ssrElementAttribute("data-id", id))
with a hoisted skip predicate per key set; the string is a literal when
every part is static. No later source can override a trailing attribute,
so output is unchanged. Child properties, textarea value, reserved
namespaces and JSX-valued attributes stay sources.
- A spread element's source literal with getters
(`<li data-id={id} class="row" {...rest}>`) is marked for hoistProps and
compiles to the same hoisted constructor as component props.
Runtime (@solidjs/web):
- ssrElement takes an optional trailing `attrs`: a string, or a thunk called
after the source walk and before the children — where the trailing
source's getters were read, so hydration ids keep their order (spec: a
server memo in the tail yields the same _hk sequence as the getter and
template forms).
- ssrElementAttribute(key, value): one attribute by the spread walk's rules,
for compiler-emitted tail thunks.
- Void-tag test and attribute-name escape cached per name; plain single
source read and keyed in place.
Runtime (@solidjs/signals):
- merge(): presized source arrays; the get trap walks plain sources
directly, reading before the `in` check.
spread-static-tail server bench, 500 rows (ops/s, Babel):
tail {...a} class 5,038 -> 5,057
head class {...a} 3,646 -> 3,661
mixed {...a} class data={id} 3,115 -> 3,790 (hoisted source) -> 4,437 (thunk) 1.42x
dynhead data={id} class {...a} 2,821 -> 3,418 1.21x
Co-authored-by: Claude via Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
* perf(web): ssrElement remembers one record per tag and reads every source body directly
Per tag name one cached TagInfo — `<tag`, `</tag>`, void, textarea, raw-text —
in place of building both strings and testing the name per element (the tag
work was 13 of the 22 ns/element over a hand-written writer). The source-kind
dispatch leaves the key loop: sourceGet was `s[key]` for every kind ssrElement
sees, so each body is read as props[prop]; only the key list depends on kind
(Reflect.ownKeys through one trap for a store/foreign proxy, as sourceKeys
did, else Object.keys). No second loop, no output change.
Isolation (btn-variant inputs vs a yak-shaped writer): 70 -> 60 µs/1000
elements, 1.46x -> 1.18x, 22 -> 9 ns/element.
Test: a store and a foreign proxy as the single source are walked through one
ownKeys trap and get, never a descriptor trap.
Co-authored-by: Claude via Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
* fix(signals): narrow the merge trap's table state so the package typechecks
The inlined read trap kept `view.table` (number | Map | null) in one binding
through the branch that reaches `table.get`, so `pnpm build` in signals
exited 2 while rollup still emitted JS. Read the state once and give the
table its own binding.
Co-authored-by: Cursor <[email protected]>
* perf(signals): one `$RECORD` read classifies a proxy source — views answer their record, stores answer undefined on the fast path
A `$PROXY`-marked source was classified by `$TARGET`, then `$VIEW`, then
`$OMIT`: two to four trap hops per source at every merge(), omit(),
isStatic and ssrElement. One brand symbol the merge and omit traps answer
first and the store trap answers undefined in its symbol branch replaces
the three private ones. merge over an omit view 81 → 50 ns, omit over a
merge 63 → 36 ns, ssrElement on a view −8%. A branded proxy that predates
the key forwards it to a target without it: still a leaf, one read.
Co-authored-by: Cursor <[email protected]>
* chore(size): audit note for ssrElement/merge at the writer floor (#3562)
signals: + createStore: cap unchanged at 16.90 KB (set by #3584), measured at 16,891 B against next's 16,866 (+25 B; 9 B under the cap) — merge()'s presized source arrays and the $RECORD classification in store/utils.ts.
Every other scenario is within its cap: core floor 0 B, isPending/latest +31 B, every-store-family app +32 B, CSR observe +11 B (prop mangler short names / brotli layout), the rest 0 B. The observe + attribution cap was re-set by #3587 on next; this PR adds 0 B there.
Co-authored-by: Claude via Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
---------
Co-authored-by: Claude via Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
SSR element and props-view fast paths for the per-element hot path. `ssrElement` takes an optional trailing `attrs` — attribute markup the caller already holds (a spread element's trailing attributes, a class a library computed and knows is clean), a string or a thunk called after the sources are walked — appended after the props' attributes in place of a `{ class, style }` source that was built, keyed and precedence-walked on every render; `ssrElementAttribute(key, value)` (compiler primitive) serializes one attribute by the spread walk's rules for such a thunk. Per tag name, `ssrElement` remembers one record — the `<tag` and `</tag>` markup, void, textarea, raw-text — in place of building both strings and testing the name on every element; the attribute-name escape is remembered per name; and every source body is read as `props[prop]` (a plain read or the proxy's trap, which is all the source helper did for these kinds), with only the key list depending on the source's kind. On a button with four props, a skip predicate and a computed class, `ssrElement` runs within 9 ns/element of a hand-written writer that knows its tag and keys (from 22). `merge()` sizes its source arrays up front and its `get` trap walks plain sources directly, reading before the `in` check. A `$PROXY`-marked source is classified by ONE read of a new internal brand, `$RECORD` — a merge or omit view answers its record, a store answers `undefined` on its symbol fast path, a proxy that does not know the key forwards it to a target without it — where `$TARGET` and then each view kind was two to four trap hops per source at every `merge()`, `omit()`, `isStatic` and `ssrElement` (a merge over an omit view: 81 → 50 ns; an omit over a merge: 63 → 36 ns; `ssrElement` on a view: −8%). The private `$SOURCES`/`$OMIT`/`$VIEW` symbols are retired for it; a store-shaped proxy that implements the brand protocol should answer `$RECORD` with `undefined` to keep the read off its generic path. No output changes.
SSR: attributes written after an element's last spread are markup, not a source. `<li {...rest} class="row" data-id={id}>` compiles to `ssrElement("li", rest, …, _sk$, () => ' class="row"' + ssrElementAttribute("data-id", id))` — statics written as the template path writes them, dynamics through `ssrElementAttribute` (the spread walk's rules for one key), the whole string a literal when every part is static — with a hoisted skip predicate (`var _sk$ = k => k === "class" || k === "data-id"`, one per key set) so the spread's own copies of those keys are never read or emitted. No later source can override a trailing attribute, so the output is unchanged; the thunk runs where the trailing source's getters used to be read, so hydration ids keep their order. What goes away per element is the trailing object literal (with getters, a dictionary-mode object and a closure per getter), its key list, and the precedence check on every key of the spread — an element whose only other source is the spread now serializes from one plain object. Attributes before a spread stay a source, and a source literal with getters (`<li data-id={id} class="row" {...rest}>`) now compiles to the same hoisted constructor as a component's props (`hoistProps`). Spread-static-tail server bench, 500 rows: statics after the spread 1.31×; a dynamic and a static after the spread 1.42× (1.22× from the hoisted source form, 1.17× from the thunk on top); the same attributes before the spread 1.21×. Child properties (`innerHTML`, `textContent`, `children`), a textarea's `value`, reserved namespaces and JSX-valued attributes stay sources.
0 commit comments