Skip to content

perf(compiler): name lynx create-function locals by depth (#86) - #95

Merged
Huxpro merged 1 commit into
new-lynxfrom
perf/lynx-template-local-naming
Aug 19, 2026
Merged

Huxpro merged 1 commit into
new-lynxfrom
perf/lynx-template-local-naming

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Summary

target: 'lynx' emits a create function per template, giving every host node a
local named from a per-node counter — n0, n1, … n240. So two structurally
identical 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.a that appends
it, 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:

fixture raw vs interpreted gzip vs interpreted
toolbar-4 −3.6% +14.9%
toolbar-40 −7.7% +81.5%
toolbar-120 −6.8% +128.6%

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-size treats the ≤1.5× median as an L5 hard gate, and
that 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:
    lynxTemplateCreateStatementsAst takes a depth and names its local n${depth},
    declaring with let on 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:

fixture raw vs interpreted gzip vs interpreted
toolbar-4 −5.6% +4.8%
toolbar-40 −14.0% +1.8%
toolbar-120 −15.0% −2.9%

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:

AssertionError: expected [ 'n0', 'n1', 'n10', 'n100', …(237) ] to deeply equal
                         [ 'n0', 'n1', 'n2', 'n3', 'n4', …(4) ]
AssertionError: toolbar-4 gzip ratio: expected 1.152073732718894 to be less than 1.1
Tests  2 failed (2)

Restored: 2 passed.

  • pnpm typecheck
  • pnpm sync (no generated changes)
  • pnpm format:files on every changed path
  • pnpm vitest run --project octane --project octane-prod --project lynx —
    866 files / 12,798 tests passed, including the L1 differential in
    lynx-target-templates.test.ts that proves the template and plan encodings
    render deep-equal first-screen batches
  • pnpm test — 20,970 passed, 4 failed. All four are among the five
    pre-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: drei upstream-e2e (fetches
    raw.githack.com), rspeedy-plugin native-demo (already named in issue
    Execution plan (#58): complete L2, then drive L4→L6 — full context handoff #66 §2), rspeedy-plugin-octane browser web-host, and octane browser
    suspense-hydration. dropzone's hydration probe, the fifth, passed this
    run — it is flaky here rather than consistently red

Measurement

Real app. lynx-table has one small row template, so it sits at the shallow
end 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 const
becoming let has to be paid for. Mount-create FCP@10000, same window, fresh
page per sample, AB/BA, n=5, quiet host (1-minute load 0.28):

cell median ms min–max
base (per-node locals) 1604.1 1547.5–1687.4
candidate (depth locals) 1584.6 1524.0–1607.3
octane-direct (L0 architecture floor) 975.5 958.7–990.3

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

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

`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
Huxpro changed the base branch from fix/lynx-first-screen-event-collision to new-lynx August 19, 2026 18:31
@Huxpro
Huxpro marked this pull request as ready for review August 19, 2026 18:31
@Huxpro
Huxpro merged commit 955258d into new-lynx Aug 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant