Skip to content

perf(bindings): select a scalar-only adopter for fixed-node DOM bindings - #1286

Merged
trueadm merged 1 commit into
mainfrom
perf/scalar-dom-binding-adopter
Sep 23, 2026
Merged

trueadm merged 1 commit into
mainfrom
perf/scalar-dom-binding-adopter

Conversation

@trueadm

@trueadm trueadm commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Fixed-node 'use dom bindings' views whose channels are all attr, boolean, aria, class or text now compile to a new __adoptScalarBindings instead of __adoptBindings. This covers both adopt-only artifacts and the scalar SSR adoption inside mountable artifacts.
  • The docs' adoptBindings example (PrimaryAction) drops from 5,864 to 3,458 B gzip (−41%). Views with any other channel keep the general adopter.

Refs #1284 (proposal 4; triage and measurements in this comment).

Why

__adoptBindings is one function that handles every capability: projections, controls, class groups, style restoration, host handoff, addressed topology and URL sanitization. Every fixed-node consumer shipped all of it. For a text/attribute view it was 12.6 KB of a 15.2 KB bundle. The compiler already knows each descriptor's channel kinds and capabilities, so it can prove when none of that is needed.

Changes

  • dom-bindings.ts:
    • Split the fixed scalar subset out of normalize, write and node resolution (normalizeFixedScalar, writeFixedScalar, resolveFixedNodes). The general functions delegate to these, so each rule has one source.
    • Add __adoptScalarBindings. It keeps the lifecycle of the general adopter:
      • snapshot and projection validation;
      • signal-handle connections and native transition preview/commit;
      • the canonical shared claims (__claimBinding/__releaseBinding) and legacy claim publication;
      • abort and dispose ordering, and error cleanup.
    • The new adopter refuses any descriptor with another channel kind, addressed, handoff or connectProjection before claiming or subscribing. Version skew or misuse therefore can't write an unsanitized URL or drop ownership behavior.
  • compiler/dom-bindings.js: scalarAdopter(plan) picks the entry at both emission sites. Richer channels, addressed targets, host handoff, styles and grouped projections keep __adoptBindings.
  • __adoptBindings behavior is unchanged. It remains the compatibility entry for earlier compiler output.
  • verify-dist.mjs: the new export is required in the published build.

Measurements

Production esbuild bundles (minified, NODE_ENV=production, gzip-9 / Brotli-11). The baseline is this branch's base 0185cb217, built from a git archive of packages/octane/src:

Consumer Baseline raw / gz / br Candidate raw / gz / br gzip delta
Docs PrimaryAction via adoptBindings 15,387 / 5,864 / 5,266 8,095 / 3,458 / 3,119 −2,406 (−41.0%)
title + text view via adoptBindings 15,202 / 5,795 / 5,229 7,910 / 3,395 / 3,052 −2,400 (−41.4%)
Same view, adopt + mountBindings (program) 36,602 / 12,560 / 11,368 31,592 / 10,940 / 9,977 −1,620 (−12.9%)
URL view (general adopter, unchanged path) 15,187 / 5,786 / 5,208 15,326 / 5,824 / 5,252 +38 (+0.7%)
export { __adoptBindings } 13,823 / 5,251 / 4,743 13,962 / 5,290 / 4,765 +39 (+0.7%)
export { __adoptBindingProgram, __mountBindingProgram } 31,453 / 10,532 / 9,584 31,562 / 10,554 / 9,633 +22 (+0.2%)

Views that keep the general adopter pay +22 to +39 B gzip for the helper split, the cost of keeping one source for scalar normalization and writes instead of duplicating it.

Update timing (supplementary: happy-dom, one process, 20,000 five-channel updates, 10 alternating samples per lane, text checked afterwards): baseline general 871 ns/update, candidate general 869, candidate scalar 842. The delegation adds no measurable cost. This is not browser layout or paint evidence.

Validation

  • New packages/octane/tests/scalar-dom-bindings.test.ts: the same compiled artifact runs through the scalar adopter and through __adoptBindings (dev and prod compile, octane and octane-prod projects). Scenarios:

    • in-place writes to every channel, including text-node identity;
    • direct signal-handle updates without reading the source, handle ↔ plain switching, and release of all subscriptions on dispose;
    • atomic presentation of signal writes from an async transition Action;
    • release of claims and the source on abort, when already aborted, and after a failed snapshot;
    • notification during subscribe and disposal during getSnapshot;
    • shared claim conflicts with the general adopter in both orders;
    • refusal of URL, handoff, addressed and projection descriptors.
  • binding-handoff.test.ts now also runs every scenario on a style-free fixture, which takes the scalar adopter. The scenarios cover renderer hydration over adopted nodes, abort, text coercion and claim release.

  • Mutation checks (each applied alone, then reverted). Caught:

    Mutation Failing tests
    drop transition preview 4
    private claims 50
    skip claim publication 8
    leak signal subscriptions 4
    skip the abort listener 8
    remove the refusal guard 4
    skip claim release 16
    skip signal connection 8
    throw on entry 24 in the handoff suite alone

    The one survivor removed a re-check that the next line repeats (an equivalent mutant).

  • benchmarks/scoped-signals/bundle-boundaries.test.mjs (runs in ci:workflow:test) gets a new guard. It compiles a fixed scalar view and a URL view, both adopt-only and mountable. For each it bundles the selected artifact and a legacy artifact that swaps back to __adoptBindings, then checks:

    • the same DOM traces in happy-dom;
    • no renderer or signal graph in either;
    • zero emitted bytes from URL-sanitizing and handoff leaves in the adopt-only scalar bundle, while the URL view keeps them;
    • gzip ratio ceilings (measured 0.50 adopt-only, 0.83 mountable). The whole file passes, 29/29.
  • Nearby suites: behavior-root, behavior-root-bundle, universal-host-bindings, universal-host-binding-retention, hydration/range-boundary, hydration/text-sibling-hydrate, plus compiler bundler-compiler, production-bundle, compiler-vite-options, typescript-text-inference and native-reads. 607 passed across 17 files and projects.

  • pnpm --filter octane build: dist built and imports verified, including the new export.

  • pnpm typecheck:files on the changed and new files, pnpm format:files:check on the changed files, pnpm changeset:check and pnpm sync.

  • pnpm test, pnpm typecheck and pnpm format:check (repo-wide): left to CI.

Risk / follow-ups

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Introduces a second DOM adoption path where compile-time or runtime mis-selection could diverge from general binding behavior or bypass URL sanitization; mitigated by compiler proof, runtime refusal guards, and parity/bundle tests.

Overview
Fixed-node 'use dom bindings' views whose channels are only attr, boolean, ARIA, class, or text now compile to __adoptScalarBindings instead of always pulling in __adoptBindings. The compiler’s scalarAdopter(plan) keeps the general adopter when the plan has styles, projections, host handoff, addressed topology, or richer channel kinds (e.g. URL).

The new adopter reuses the same claims, signal connections, transition preview/commit, and dispose/abort behavior, but drops projection, controls, class groups, style restoration, and URL sanitization from adopt-only bundles—~41% smaller gzip on documented scalar examples. normalizeFixedScalar / writeFixedScalar / resolveFixedNodes centralize scalar DOM writes; the general adopter delegates to them unchanged.

__adoptScalarBindings throws if a descriptor needs capabilities it does not implement, so misuse cannot skip sanitization. Tests add scalar parity vs the general adopter, bundle boundary checks (size + DOM traces), and handoff coverage for style-free fixtures; verify-dist requires the new export.

Reviewed by Cursor Bugbot for commit f9c9ff3. Bugbot is set up for automated code reviews on this repo. Configure here.

Fixed-node 'use dom bindings' views whose channels are all attr, boolean,
aria, class or text now compile to __adoptScalarBindings. It shares node
resolution, channel claims, legacy claim publication, the signal connector
and native transition preview with __adoptBindings, but retains none of the
projection, control, class-group, style-restoration, host-handoff, addressed
topology or URL-sanitization code. The general adopter keeps its behavior and
remains the compatibility entry for earlier artifacts.

Refs #1284 (proposal 4).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review September 23, 2026 18:28
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Sep 23, 2026
@trueadm
trueadm merged commit afc0bee into main Sep 23, 2026
46 of 49 checks passed
@trueadm
trueadm deleted the perf/scalar-dom-binding-adopter branch September 23, 2026 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant