Repository navigation
feat(octane): count engine work in profile builds - #1894
Merged
Merged
Conversation
Phase 1 of #1886. Profile builds keep session totals of the work around component renders: render attempts and outcomes, bailouts, Blocks created and torn down, @if/@switch arms kept or replaced, Suspense fallbacks and error catches, render-queue passes, accepted root commits, and work discarded by rollbacks (root transactions, journal entries, captures). profiler.snapshot() carries a schema version, build, renderer set and recording generation, and profiler.diff() rejects pairs it cannot compare. Each renderer declares the counters it records, so an unsupported counter is absent rather than zero. Every probe sits behind the existing __OCTANE_PROFILE_ENABLED__ guard; optimized builds without profiling contain no added code. A DEV + PROFILING lane for the root-suspension benchmark fixture records the counters around a real hold and retry, gated on their semantics, and runs in the weekly Bench workflow. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 8, 2026 12:47
Contributor
Benchmark report
Compares js-framework: 1k/10k row operations
All 20 timed operations (19 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)No changes across 60 measured values. Public-import reachability bundles (bytes)
103 other measured values are unchanged. Lynx dual-thread render (report only)All 13 timed operations (13 without a verdict)
|
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| 🔵 In progress View logs |
octane-website | f45dd1b | Oct 08 2026, 12:59 PM |
The docs search index keeps page sections aligned with authored headings. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is phase 1 of #1886, scoped to the review's recommended first cut: a counter core with
snapshot/diff, a small counter set covering the motivating examples (wasted renders, rebuilt arms, abandoned work), the strip check, and one benchmark that drives a real interaction end to end. Hook counts, hydration counters, timeline tracks, and<Profiler>come in later PRs.Profile builds (
profile: true, ordevtools: trueundervite dev) now keep session totals of the engine work around component renders. All probes sit behind the existing__OCTANE_PROFILE_ENABLED__guard; there is no second flag.component.rendercomponent.renderSuspended/component.renderErroredcomponent.bailoutblock.create/block.unmountarm.keep/arm.swap@if/@switchevaluations that re-rendered the current arm, or replaced it. A slot's first arm is not a swapboundary.fallback/boundary.catchscheduler.draincommit.rootrollback.rootrollback.journalEntries(log.length − checkpoint) / 4, sampled before replayrollback.captureCounters measure attempted work, so a render a later rollback discards still counts.
Changes in response to the review on #1886:
commit.rootcounts acceptance rather than entry. The root-shape retry in the benchmark commits with zero drains: it re-renders outside the queue.API
The API lives on
octane/profilingandglobalThis.__OCTANE_PROFILER__; nothing is added tooctane.counters()returns the current totals.snapshot()returns the totals with an envelope:schema, recordinggeneration,build,renderers,recording, andtime.diff(before, after)throws when the snapshots cannot be compared:stop()orclear()between them;Each renderer declares the counters it records when its module loads:
domdeclares all 15, anduniversalonly the render counters. A counter that no installed renderer records is absent from a snapshot, not zero.Counters are session totals, so evicting buffered events never shrinks them; only
clear()resets them. In profile builds a probe is one increment into a preallocatedFloat64Arrayand allocates nothing per event.Benchmark lane
benchmarks/lib/profile-counters.mjsmirrors the precise-coverage collector. Each sample:benchmarks/suspense-recovery/profile-counters.mjsruns the existing root-suspension fixture, its controls and verification as a DEV + PROFILING build. The controls are now shared withroot-work.mjsthroughroot-controls.mjs; the serialized adapter is byte-identical, so root-work's recordedadapterHashdoes not change. The lane gates semantics: every hold rolls back exactly one root render without committing, and every retry commits once without a rollback. The weekly Bench workflow runs it, along with the collector's unit tests.Profile builds compile the generic program, so this lane complements the production precise-coverage lane and does not replace it.
Validation
profiling.test.ts,profiling-disabled.test.tsrx,production-profile-bundle.test.ts(octane): 19 passed.profiling-runtime.test.tsrx(octane-profile): 21 passed.universal-native.test.ts -t profil(octane): passed.runtime.tsfailed the three matching runtime tests; restored afterwards.node --test benchmarks/lib/profile-counters.test.mjs benchmarks/lib/precise-work.test.mjs: 11 passed.node benchmarks/suspense-recovery/profile-counters.mjs, one local run: all 10 shape/operation samples passed their gates. For example,branch/holdgaverollback.root 1, commit.root 0, arm.swap 1, rollback.journalEntries 16, rollback.capture 1.pnpm --filter octane build: dist imports verified.dist/node/profiling.jsreads the module-level__octaneDevflag.pnpm typecheck:fileson the changedsrcfiles: clean. In the tests, the only new error (count as string) is fixed; the others predate this branch, and tests are excluded frompackages/octane/tsconfig.json.pnpm sync(no generated changes),pnpm format:files:check.pnpm test,pnpm typecheck,pnpm format:check: left to CI.Strip check. I bundled
src/index.tsandsrc/universal.tsfrommainand from this branch with esbuild,__OCTANE_PROFILE_ENABLED__: false, andNODE_ENVset to production and then development, using the same tsconfig and source paths of equal length:index.tsuniversal.tsindex.tsuniversal.tsThe compressed deltas come only from minified-identifier assignment: two module-level
WeakMaps swap their short names. That is the review's distinction made concrete:if (false)code that never runs.The first version of this check caught a real leak: top-level
new Float64Array(COUNTER_NAMES.length)retained the name table in builds that ignoresideEffects. It is now@__PURE__with a literal, type-checked length.CI bench report (comment):
perf-review
Perf review: feat/profile-counters (8444db8..worktree)
Scan:
node scripts/perf-review-scan.mjs→ 0 candidates.Hot paths touched (each change is a guarded probe; the code is identical when profiling is off):
createBlock,unmountBlockInner: per Block.renderBranchSlot: per@if/@switchevaluation.setTryBranch: per boundary transition.drainQueue: per flush.commitRootRenders: per root commit.rollbackRootRender,rollbackTransitionJournal,discardOffscreenCapture: rollback paths.packages/octane/src/runtime.ts(newprofiling.jsimports)__OCTANE_PROFILE_ENABLED__guardsmainpackages/octane/src/profiling.ts(counter tables)@__PURE__with a literal length, so builds that ignoresideEffectsdrop themProfileEventallocation that dominatesShapes: no new field on
BlockImpl,ScopeImpl, orLiteBlockImpl. Per-capture deduplication uses a moduleWeakSet, the same pattern astrackedComponents. DOM and scheduling: no change. Compiled output: no compiler change.Risk / follow-ups
getCommits(), delayed effects attributed to their originating commit) needs commit identities distinct fromDRAIN_ID; the counters keep those identities separate so that work can build on them.resolveSlot,use(),useContext);<Profiler>as its own milestone, including keyed identity when profiling is off;profile: 'counters'(counters over unmodified production output) remains an open question on the issue. The precise-coverage lane stays the production oracle.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Instruments core DOM runtime paths (commits, rollbacks, scheduler, boundaries) behind the profile guard; production non-profile bundles are intended unchanged, but counter semantics on rollback/commit are easy to get wrong.
Overview
Profile builds now accumulate session engine-work counters (renders, bailouts, blocks,
@if/@switcharms, boundaries, queue drains, root commits/rollbacks, journal replay, discarded captures) alongside the existing event buffer. The profiler gainscounters(),snapshot(), anddiff(before, after)with schema/build/renderer/generation checks; renderers register which counters they record at load time (domall 15,universalrender-only). Counters are absent when not recorded, survive event-buffer eviction, and reset only onclear().Runtime wires guarded probes in
runtime.ts(and universal render counters inuniversal-core.ts) behind__OCTANE_PROFILE_ENABLED__, including component render outcomes on__profileEndRender.Benchmarks & CI: shared root-suspension page controls in
root-controls.mjs;collectProfileCountersmirrors precise-work timing;profile-counters.mjsruns the fixture in DEV+profiling and asserts hold = onerollback.root, retry = onecommit.root. Weekly Bench workflow runs collector tests and the new lane so counter semantics cannot rot.Docs/tests: profiling docs and changeset describe the API; unit/runtime/bundle tests cover diff validation, DOM counter behavior, and production strip behavior.
Reviewed by Cursor Bugbot for commit 73b61f9. Bugbot is set up for automated code reviews on this repo. Configure here.