Skip to content

perf: avoid signal ownership and Action code in ordinary roots - #1135

Merged
domgan-oai merged 4 commits into
octanejs:mainfrom
openai-oss-forks:codex/perf-signal-free-runtime-1130
Sep 18, 2026
Merged

domgan-oai merged 4 commits into
octanejs:mainfrom
openai-oss-forks:codex/perf-signal-free-runtime-1130

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An opaque scalar prop could enable document-wide signal ownership, and every ordinary root retained the concrete signal Action implementation through function-form Actions. Defer ownership until a real handle appears, preserve primitive value proofs through extracted JSX props, and register model Action frames from the signal graph instead of importing their constructor into the renderer.

Refs #1118 and #1130 §2.1. This recovers a measured part of the unused-signals regression; it does not close either issue or restore the entire pre-#1069 bundle size.

Changes

  • Opaque text, attributes, controls, child values and host spreads keep their handle capability without eager ownership. Actual handles and native reads retain activation.
  • Generated value holes preserve JavaScript primitive proofs. Casts, unknown props, uncertain branches, shadowed coercion calls and forwarded handles remain capable of carrying signals.
  • Separate model transactions from optional native forwarding leases. A live factory registration admits signals loaded after an async Action starts and preserves synchronous staged reads, urgent rebasing, disposal and atomic presentation.
  • Add production closure, primitive codegen and allocation guards. The minimal starter observes its computed layout instead of assuming the first emitted stylesheet contains its page styles. No byte budgets or ratio thresholds change.

Size evidence and tradeoff

After the key and scoped-stylesheet fixes landed, matched ordinary production builds use exact Git archives of main @ 9b22cffd and candidate 39e8e7b9, identical fixture/package/lock hashes, Node 24.19, Vite 8.1.5 and esbuild 0.28.1. The subsequent website-only main advance leaves Octane source and tests byte-identical. Whole gzip closures:

Fixture Main Candidate Delta
root-static 65,968 62,583 −3,385
hooks-state 68,780 65,394 −3,386
context 71,950 68,606 −3,344
hydrate-root 84,891 81,503 −3,388
suspense-transition 81,973 78,571 −3,402
deferred-hydration 96,612 93,135 −3,477

Both Action implementation modules emit zero bytes in an ordinary esbuild createRoot closure; optional native adapters and graph dependencies remain excluded. The production opaque-row guard preserves scalar text/title updates, keyed identity, typed input and teardown while owner freezes and identity serialization drop to zero. It fails on original main with 201 owner allocations. The source-preserving 2,000-row/20-update audit also removes 160,040 measured owner-map reads during updates.

Separate matched engine/SSR/combined-native builds against main @ 1d935515c show the tradeoff. The model implementation is moved, not made free: a standalone Vite engine closure grows 11,457 → 14,654 gzip (+3,197, +27.9%), and a representative compiled SSR+engine fixture grows 27,970 → 30,785 (+2,815, +10.1%). Neither reaches the native forwarding module. A combined native renderer+engine app is nearly unchanged: 91,656 → 91,800 (+144, +0.16%), with real urgent and transition updates, survivor identity and cleanup verified. These are separately built closures; compressed totals are not summed. No SSR CPU improvement is claimed.

Validation

  • Compiler/adoption checks: 295 passed, plus 16 primitive evaluation/adoption controls.
  • Runtime/node signals checks: 333 passed across dev/prod/strong.
  • Real Vite browser suite: 4 passed in dev/prod (Chromium startup required process escalation).
  • Production boundary/allocation/codegen node guards: 18 passed; all eight signal-free minimal application lanes pass observable-behavior checks.
  • Final current-main lifecycle, direct-binding adoption and textarea checks: 237 passed. The completed lifecycle matrix separately passes 12/12, including native function-form submission with writes before/after await; omitting only the factory causes immediate early publication.
  • Post-merge owning control/lifecycle matrix: 266 passed; combined integration of all five selected PRs: 1,629 passed with frozen ASTs. Cold module bootstrap is fixture setup with the Action already running; all synchronous reads, held publication, urgent updates and disposal assertions remain in the tests. No timeout or concurrency settings change.
  • Scoped source/new-test types, strict JSX fixture types, formatting, pnpm sync and diff checks passed. Existing compiler-test @tsrx/core TS7016 is reproduced on original main; no declarations or type rules are weakened. Full repository tests/typecheck are delegated to current-head CI.

Risk / follow-ups

The standalone signals/SSR parse-load increase is material and explicit. Avoiding the implementation in both independent engine and renderer closures requires a further capability/loading architecture; async initialization or import-name gating would change supported behavior. Remaining renderer signal branches and SSR ownership costs are outside this patch, so the full reported 21% regression is not described as fixed.

Provenance

  • An agent produced this diff (agent-authored)

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
Touches compiler binding classification, transition/Action wiring, and bundle boundaries; behavior is heavily tested but incorrect primitive vs opaque classification could break signal adoption or leave stale DOM on updates.

Overview
Signal-free roots stay leaner by not turning on document-wide signal ownership or pulling transition Action code unless a binding is actually a signal handle. Opaque props can still use signal-capable paths later without paying that cost up front.

The compiler now tracks primitive value proofs on extracted JSX holes (octane_primitive_value), so expressions like String(props.x) skip bindSignal* codegen and eager enableSignalBindings, while casts, bare props, and uncertain branches stay signal-capable. Eager activation is limited to direct handle expressions (inputs, children, host spreads).

Runtime packaging splits the model SignalActionFrame into transition-action.ts, registered from the signal graph via registerSignalActionFrameFactory. Ordinary createRoot bundles can tree-shake transition-action / heavy candidate logic; native presentation installs via installNativeSignalActionExtension when the native read driver starts. Late octane/signals import during a pending Action still gets a frame from the factory.

Guards extend minimal bundle reachability, scoped-signal boundaries (zero emitted bytes for transition modules on signal-free clients), allocation tests for scalar list rows, primitive codegen matrix, hydration adoption, and Action lifecycle (urgent updates, form actions, forwarded handles).

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

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Sep 18, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review September 18, 2026 21:06
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