Skip to content

perf(compiler): index component hoist references once - #863

Merged
trueadm merged 1 commit into
mainfrom
fix/index-component-hoist-references
Aug 26, 2026
Merged

trueadm merged 1 commit into
mainfrom
fix/index-component-hoist-references

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • index component-name occurrences once per module instead of sanitizing and scanning every growing source prefix once per component
  • preserve the existing client/server declaration-hoisting contract, including string/comment blindness and template-interpolation TDZ safety
  • extend the 2,400-component graph benchmark with declaration-shape correctness guards

Why

Component-heavy modules repeatedly answered the same lexical question for every component: “was this component referenced above its declaration?” Each answer sliced, sanitized, and regex-scanned a larger prefix of the module. A single indexed source pass removes that accidental quadratic work.

Clean same-machine A/B against the original base:

  • dependent-first: 1096.258 ms → 819.938 ms (-25.2%)
  • dependency-first: 1030.190 ms → 749.841 ms (-27.2%)

Changes

  • collect first reference offsets for ordinary top-level component names during compiler setup
  • share the indexed decision between client and server lowering, retaining the historical fallback for uncommon identifier spellings
  • cover independent real and string/comment-only names in both compile modes
  • assert expected hoisted declaration counts in tsrx-component-graph
  • add an octane patch changeset

Validation

  • pnpm format:check (scoped check run instead)
  • pnpm typecheck (Octane source and typetest projects run instead)
  • pnpm test (attempted locally; unrelated browser/localStorage/timing failures accumulated before the Vitest coordinator exhausted its 4 GB heap)
  • pnpm sync
  • pnpm format:files:check benchmarks/tsrx-component-graph/README.md benchmarks/tsrx-component-graph/run.mjs packages/octane/src/compiler/compile.js packages/octane/tests/component-hoisting.test.ts .changeset/fast-component-hoist-scan.md
  • tsgo --noEmit -p packages/octane/tsconfig.json
  • tsgo --noEmit -p packages/octane/typetests/tsconfig.json
  • targeted tests: 3 files / 25 tests passed for component hoisting and production bundles
  • node benchmarks/bench.mjs --quick --ratios tsrx-component-graph

Risk / follow-ups

  • Risk is limited to compiler declaration-shape classification. The focused tests pin client/server behavior, and the benchmark refuses samples unless both declaration orders emit the expected hoisted-function counts.
  • Current-head CI should provide the repository-wide test result that the local browser/platform environment could not.

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
Changes compiler declaration-shape classification for every component module; wrong indexing would cause TDZ crashes or lost tree-shaking, though tests and benchmark guards target that contract.

Overview
Replaces per-component prefix sanitizing and regex scans with a single module pass that records the first source offset of each top-level component name, then reuses that index when deciding whether to emit a hoisted function vs a const initializer on both client and server lowering.

Behavior stays the same for strings/comments (ignored), template interpolations (still count as references), and uncommon identifier spellings (still use the historical prefix scan). New hoisting tests cover multi-name classification in both modes; the 2,400-component graph benchmark now asserts expected hoisted-declaration counts per declaration order so regressions in above-declaration detection fail the harness.

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

@jonkwheeler
jonkwheeler marked this pull request as ready for review August 26, 2026 17:09
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Aug 26, 2026
@trueadm
trueadm merged commit efdc8cb into main Aug 26, 2026
51 checks passed
@trueadm
trueadm deleted the fix/index-component-hoist-references branch August 26, 2026 17:57
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.

2 participants