Repository navigation
perf(compiler): name lynx create-function locals by depth (#86) - #95
Merged
Merged
Conversation
`target: 'lynx'` gave every host node in a create function a local named from a per-node counter, so two structurally identical siblings emitted two blocks differing only in the bytes of their identifier — which is exactly what LZ77 matches on. The gzipped encoding therefore grew without bound in node count. A host local is live only from its own creation until the `env.a` that appends it, and that window nests exactly with tree depth, so siblings can share a name. Naming locals by depth makes repeated subtrees byte-identical. Measured on a toolbar ladder compiled at both targets. Raw output was already the smaller of the two at every width, so nothing about the encoding was verbose; the penalty was purely a compression effect: toolbar-4 gzip +14.9% -> +4.8% raw -3.6% -> -5.6% toolbar-40 gzip +81.5% -> +1.8% raw -7.7% -> -14.0% toolbar-120 gzip +128.6% -> -2.9% raw -6.8% -> -15.0% This is the measurement half of #86. Section 8 recorded the trade as "10-22% larger because repeated JSON keys compress better than code"; both halves of that sentence were wrong, and the doc is corrected rather than rewritten. Because the penalty scaled with template size, it was not a trade the L5 re-audit could have repaid by deleting the interpreter. The test pins the structural property first — a 4-button and a 120-button toolbar are both three levels deep, so their create functions must use the same identifiers — and the compression ratio second. Reverting to a per-node counter yields 241 distinct locals instead of 4 and a 1.152x ratio. lynx-table has one small row template and so sits at the shallow end: gzipped bundles shrink 273 B (web) and 367 B (lynx). Same-window FCP@10000, n=5, quiet host: 1604.1 ms (1547.5-1687.4) before versus 1584.6 ms (1524.0-1607.3) after, overlapping ranges — no runtime change, which is what `const` becoming `let` had to establish. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
Huxpro
changed the base branch from
fix/lynx-first-screen-event-collision
to
new-lynx
August 19, 2026 18:31
Huxpro
marked this pull request as ready for review
August 19, 2026 18:31
6 tasks done
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
target: 'lynx'emits a create function per template, giving every host node alocal named from a per-node counter —
n0,n1, …n240. So two structurallyidentical siblings emit two blocks that differ only in the bytes of their
identifier, and that is exactly what LZ77 matches on. The result is a gzip
penalty that grows without bound in node count.
A host local is live only from its own creation until the
env.athat appendsit, and that window nests exactly with tree depth. Siblings can therefore share
a name. Naming locals by depth makes repeated subtrees byte-identical.
Closes the measurement half of #86.
Why
§8 recorded the L1 size trade as "gzip 10–22% larger on the fixture modules
because repeated JSON keys compress better than code — accepted as an L1 trade,
re-audited at L5". #86 argued both halves of that sentence are wrong. They are.
Compiled at both targets, a toolbar ladder gives:
Raw output is smaller at every width — so nothing about the encoding is
verbose. The penalty is purely a compression effect, and it scales with node
count rather than sitting in a 10–22% band. Both fixtures §8 originally measured
happened to sit at the shallow end.
benchmarks/lynx-bundle-sizetreats the ≤1.5× median as an L5 hard gate, andthat gate is sized against the interpreted encoding L5 is supposed to delete.
A trade that grows with template size is not one that can be repaid by deleting
the interpreter.
Changes
packages/octane/src/compiler/compile-universal.js:lynxTemplateCreateStatementsAsttakes a depth and names its localn${depth},declaring with
leton first use at that depth and assigning afterwards.packages/octane/tests/lynx-target-template-size.test.ts: the gate.Validation
After, on the same ladder:
The growth is gone, and at 120 nodes the create-function encoding is now the
smaller of the two gzipped as well as raw.
The new test pins the structural property first — the set of identifiers a
create function uses must be identical for a 4-button and a 120-button toolbar,
because the toolbar is three levels deep either way — and the compression ratio
second (≤1.10× across the ladder). Pinning the mechanism rather than only the
bytes is what keeps the gate meaningful if the emitter changes shape.
Red-green, reverting to a per-node counter:
Restored: 2 passed.
pnpm typecheckpnpm sync(no generated changes)pnpm format:fileson every changed pathpnpm vitest run --project octane --project octane-prod --project lynx—866 files / 12,798 tests passed, including the L1 differential in
lynx-target-templates.test.tsthat proves the template and plan encodingsrender deep-equal first-screen batches
pnpm test— 20,970 passed, 4 failed. All four are among the fivepre-existing container failures established on PR perf(lynx): classify host updates without building the prop patch (issue-66 A4) #92 by re-running them on
the base commit
c3baf805a:dreiupstream-e2e (fetchesraw.githack.com),rspeedy-pluginnative-demo(already named in issueExecution plan (#58): complete L2, then drive L4→L6 — full context handoff #66 §2),
rspeedy-plugin-octanebrowserweb-host, andoctanebrowsersuspense-hydration.
dropzone's hydration probe, the fifth, passed thisrun — it is flaky here rather than consistently red
Measurement
Real app.
lynx-tablehas one small row template, so it sits at the shallowend of the ladder; the win there is correspondingly small and is reported as
such. Gzipped bundle: web −273 B, lynx −367 B.
Runtime. The emitted program is what runs on the Lynx main thread, so
constbecoming
lethas to be paid for. Mount-create FCP@10000, same window, freshpage per sample, AB/BA, n=5, quiet host (1-minute load 0.28):
octane-direct(L0 architecture floor)0.988× with overlapping ranges: no runtime change, which is the claim this
needed to support. Committed as
benchmarks/lynx-table/prototype/results/fcp-10000-template-naming.md.Risk / follow-ups
silently rewritten: it now says what it originally claimed and that both halves
were wrong, and points at the new entry.
env.a.If a future emitter keeps a host local live past its append — a sibling
cross-reference, say — this is the assumption that breaks, and the structural
test is what will notice the identifier count moving.
letrather thanconstis what allows the reuse. Nothing captures thesebindings, so there is no closure-per-iteration hazard.
budget numbers should be re-derived now that the trade is gone. That is an
L5 question and is left to the L5 re-audit.
Provenance
agent-authored)Generated by Claude Code