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 1735074
Browse filesBrowse the repository at this point in the historyBrowse files
perf(compiler): SSR props literals with getters compile to hoisted constructors (hoistProps) (#3550)
A component's props literal with getters — the compiler's own `{ get x() {
return sig() }, ... }` — is built by V8 in dictionary mode with a closure
per getter per instance. With `hoistProps` (default on) both compilers emit
a module-level constructor whose getters live on the prototype and read
their captures through symbol slots on the instance; the call site becomes
`new _P$(a, b)`. Own keys, order, descriptors and prototype are unchanged,
so `Object.keys`, spread, `hasOwn`, `isStatic()` and `hasStaticKeys()`
answer as before.
The contract that changes: a props getter is defined only for a read
through its own object. Copying its descriptor onto another object
(`Object.defineProperty(target, k, getOwnPropertyDescriptor(props, k))`)
no longer works; in dev the getter throws naming the rule. Our own
primitives never copy descriptors except omit()'s no-Proxy fallback, fixed
in #3544 to re-home accessors.
Sites the pass leaves as literals: getters that close over a binding that
is reassigned or declared after the site, `this`/`super`/`arguments`, or a
module-level site (nothing to hoist above). Compiled template temps that
belong to a single getter move into it.
Babel (`src/ssr/props.ts`) and the native compiler (`src/ssr/props.rs`)
emit byte-identical output, including Babel's `_p`, `_p2`…`_p9`, `_p0`,
`_p1`, `_p10` parameter sequence; the native compiler additionally marks
the IIFE it generates for module-level `this` capture as transparent to
the depth rule, which Babel does not need.
Measured (yak-bench, SSR CPU per render, native compiler, mprim lane):
component-heavy pages +15–31%, geomean 1.12×; Octane ssr-throughput and
streaming-ssr flat (element-heavy fixtures, no getter literals on the hot
path).
Co-authored-by: Claude via Cursor <[email protected]>
SSR: a component's props literal with getters compiles to a module-level constructor with shared getters (`hoistProps`, default on) instead of an object literal, which V8 builds in dictionary mode with a closure per getter per instance. Same own keys, order, descriptors and prototype; a props getter is now defined only for a read through its own object — copying its descriptor elsewhere throws (dev names the rule). Sites closing over a reassigned or later-declared binding, `this`, or `arguments` keep the literal. Babel and the native compiler emit the same output.
Copy file name to clipboardExpand all lines: packages/babel-plugin/README.md
+28Lines changed: 28 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -250,6 +250,34 @@ Inline style attributes in templates when the value is a string or `Record<strin
250
250
251
251
SSR-only: emit behavior-claim (`_bnd`) markers for `ref` / `on*` on intrinsic elements.
252
252
253
+
### hoistProps
254
+
255
+
- Type: `boolean`
256
+
- Default: `true`
257
+
258
+
SSR-only: a component's props literal with getters compiles to a module-level constructor whose getters are shared across instances, instead of an object literal (which V8 builds in dictionary mode, allocating a closure per getter per instance):
259
+
260
+
```js
261
+
var _m$ =Symbol();
262
+
var _d$ = {
263
+
get() {
264
+
constprops=this[_m$];
265
+
returnprops.label;
266
+
},
267
+
enumerable:true,
268
+
configurable:true
269
+
};
270
+
function_P$(_p, _p2) {
271
+
this[_m$] = _p;
272
+
this.as= _p2;
273
+
Object.defineProperty(this, "label", _d$);
274
+
}
275
+
_P$.prototype=Object.prototype;
276
+
Comp(new_P$(props, "a"));
277
+
```
278
+
279
+
The instance has the same own keys, order and descriptors as the literal and `Object.prototype` as its prototype; `Object.keys`, spread, `hasOwn` and `isStatic()` answer as before. One contract follows: a props getter is defined only for a read through its own object (`props.x`, spread, `merge()`/`omit()`). Copying its property descriptor onto another object and reading it there throws — define a getter that reads through the source instead. Sites whose getters close over a binding that is reassigned, declared after the site, or `this`/`arguments` keep the literal. `false` keeps the literal everywhere.
280
+
253
281
## TSRX (experimental)
254
282
255
283
TSRX (TypeScript Render Extensions) is a syntax for declarative UI. `.tsrx` sources desugar to the same Solid JSX this plugin already compiles: `@if`/`@else`, `@for … @empty`, `@switch`/`@case`, and `@try`/`@catch`/`@pending` lower to the corresponding control-flow components (`Show`, `For`, `Switch`/`Match`, `Errored`, `Loading`), and `@{}` statement containers mix setup statements with rendered elements.
0 commit comments