Skip to content

bench(lynx): attribute the FCP residual at the Element PAPI boundary - #52

Draft
Huxpro wants to merge 1 commit into
mainfrom
claude/issue-50-39v4y1
Draft

Huxpro wants to merge 1 commit into
mainfrom
claude/issue-50-39v4y1

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes #50.

stages/run.mjs decomposes Octane from inside Octane, so its segments stop at
the Element PAPI call and everything past it — prop and insertion work,
__FlushElementTree, Web Core DOM publication, style/layout, observer delay —
landed in one layout_flush_residual, 60.9% of FCP@10k, uncomparable against a
framework whose internals are not instrumented.

This adds the other side of the same call. @lynx-js/web-core installs the whole
Element PAPI onto the hidden main-thread script realm with a single
Object.assign issued from the page (LynxViewInstance.onPageConfigReady), so
wrapping that one assignment observes the host boundary and the identical
instrument measures Octane, ReactLynx, and Vue vdom+IFR+ET by construction.

No framework is patched, no reference bundle is rebuilt, and no featured bundle
hash changes
— a host-side probe needs no instrumented reference artifact at
all.

Benchmark tooling and frozen evidence only; this PR touches nothing under
packages/. The two optimizations it authorized are split out into
#56, which reviews on its own without scrolling past ~21k lines of evidence
JSON.

Findings

Frozen in stages/results/papi-*.json, decision write-up in
stages/results/papi-report.md. n=5 per variant per cell per scale at
1k/10k/30k, fresh page per sample, zero DNF and zero null cells.

  • Octane issues the fewest host calls per row of the three cells — 20 against
    ReactLynx's 21 and Vue's 25 — perfectly linear 1k→30k (0.0% drift), one
    __FlushElementTree each. Certified create deltas against ReactLynx: +12.8 /
    −12.8 / +113.1 ms. There is no create-side deficit to attribute.
  • The shared Web Core floor is genuinely shared. On the composed
    startup + create path Octane and ReactLynx land at 1,242.9 vs 1,244.5 ms at
    10k — 0.1% apart. The references carry no pre-populated first screen, so their
    FCP@N is reported not measured, never substituted.
  • The deficit is Octane's first-screen path against its own post-mount path,
    +18.8% / +33.6% / +45.0% for an identical tree — same driver, same bundle
    family, so no cross-framework confound can enter.
  • __FlushElementTree publication owns a near-constant 27.0% / 28.7% / 27.3%
    of that excess across a 30× scale range.
  • Publication op count is NO-GO, the surprise: the first screen issues +11
    host calls per row (+55%) but they cost the host less than the ones they
    replace (−9.3 / −60.8 / −119.1 ms). First-paint scheduling and per-element
    stream shape are NO-GO too.

The sharpest localisation is the flush trace: between the tree reaching the DOM
and the next flush, Octane issues exactly 7 more host calls per row and nothing
else. That window is captureLynxFirstTree, 16.7–20.1% of FCP, and every
millisecond of it is pure paint delay. #56 acts on it.

How the measurement defends itself

  • Three page variants run interleaved with rotating order: control (no
    probe), counts (call counts, flush cadence, start delay, with no per-call
    clock read) and timed (per-call exclusive host time). Counts-build overhead
    stays within the declared 1.05× ceiling on every load-bearing cell; the timed
    build's 1.05–1.14× is used only for shares, never for a wall-clock claim.
  • The two builds must agree on counts, reported per cell. A probe that
    changed what the framework called would show up here as disagreement.
  • Measurement is split from reporting. papi-run.mjs writes evidence,
    papi-report.mjs renders from it, so an attribution or wording change
    re-renders checked-in JSON instead of costing another measurement window.
  • The driver's own cost is measured, not assumed. papi-predicate-cost.mjs
    records that the FCP predicate's composed-tree walk costs 54 / 720 / 2,354 ms
    — large enough to plausibly own the whole excess, which is why the report
    states exactly why it does not: x.fcp samples its timestamp before the walk,
    so the resolving walk is excluded by construction.
  • Where a term is a remainder it is named as one, including the median
    non-additivity in the delta tables, rather than presented as unexplained
    physics.

Changes

  • web/driver-client.mjs: papiInstrumentJs({ timers }) host-boundary probe;
    shellCount / shellAtLeast so a first screen with no rows has a paint
    predicate; x.fcp and x.arm carry epochs and a probe snapshot taken at the
    resolving frame; chromiumLaunchOptions() shared by every harness.
  • stages/papi-analyze.mjs + tests: grouping, the
    wall = start_delay + Σ host groups + off_boundary identity, the exact
    count-vs-rate delta split, scaling and overhead gates. 15 unit tests.
  • stages/papi-run.mjs, papi-report.mjs, papi-predicate-cost.mjs, frozen
    results.
  • stages/analyze.test.mjs: resolve the repo path from the test file rather than
    the process working directory, which made the package's own test:stages fail
    from the package directory.

Validation

  • pnpm format:check
  • pnpm typecheck
  • pnpm test — 20,670/20,919 passing. The 50 failing files fail in this
    sandbox before the diff: 55 raise Chromium could not be launched
    (image ships Chromium 1194, Playwright pins 1228), the rest are
    Port 63315 is in use and one 5 s timeout under load. Evidence in the
    comment below. Nothing here is under packages/, and vitest.config.js
    defines no project over benchmarks/, so no vitest project can reach it.
  • targeted: node --test benchmarks/lynx-table/stages/*.test.mjs — 23/23,
    from both the repo root and the package directory.
  • the reportable run itself, quiet-host preflight passed, nothing else in the
    window.

Measured on 4× Intel Xeon @ 2.10GHz, Chromium 141.0.7390.37,
@lynx-js/web-core 0.22.2. Absolute milliseconds are host-bound; op counts,
ratios, and shares are the portable claims.

Risk / follow-ups

  • Benchmark-only. No product code changes here.
  • ReactLynx and Vue FCP@N stay not measured: a pre-populated first screen is a
    build-time define of the app source, and rebuilding a reference would change
    the hash the featured runs recorded.
  • off_boundary is named but unseparated — framework first-screen script plus
    the browser's own frame after publication. Splitting it needs a framework-side
    probe on the first-screen path.

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

`stages/run.mjs` decomposes Octane from inside Octane, so its segments stop
at the Element PAPI call and everything past it lands in one
`layout_flush_residual` — 60.9% of FCP@10k, and uncomparable against a
framework whose internals are not instrumented.

Add the other side of the same call. `@lynx-js/web-core` installs the whole
Element PAPI onto the hidden main-thread script realm with a single
`Object.assign` issued from the page; wrapping that one assignment observes
the host boundary, so the identical instrument measures Octane, ReactLynx,
and Vue vdom+IFR+ET by construction. No framework is patched, no reference
bundle is rebuilt, and no featured bundle hash changes.

Three page variants run interleaved: `control` (no probe), `counts` (call
counts, flush cadence, and start delay with no per-call clock read) and
`timed` (per-call exclusive host time). Counts-build overhead stays within
the declared 1.05x ceiling on every load-bearing cell, the timed build's
1.05-1.14x is used only for shares, and the two builds' counts must agree —
reported per cell as the control on that cost.

Findings, frozen in stages/results/papi-*.json and papi-report.md:

- Octane issues the fewest host calls per row of the three cells (20 vs
  ReactLynx 21, Vue 25), perfectly linear 1k to 30k, one flush each. There
  is no create-side deficit to attribute on this host.
- Octane and ReactLynx are within 0.1% on the composed startup+create path
  at 10k, so the shared Web Core floor is genuinely shared.
- Octane's first-screen path costs 18.8%/33.6%/45.0% more than its own
  post-mount path for an identical tree. `__FlushElementTree` publication
  owns a near-constant 27-29% of that excess across a 30x scale range.
- Publication op count, first-paint scheduling, and per-element stream shape
  are each NO-GO: the +11 host calls per row the first screen issues cost
  the host less than the calls they replace.

Report rendering is split from measurement, so an attribution change
re-renders checked-in evidence instead of costing another measurement
window. `papi-predicate-cost.mjs` records what the driver's own predicates
cost, so the report can state that bound rather than leave it to be guessed.

Also fix `stages/analyze.test.mjs` resolving a repo path from the process
working directory, which made the package's own `test:stages` script fail
from the package directory.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UMisRkW6cGfodXwpy4kxYS

Huxpro commented Aug 12, 2026

Copy link
Copy Markdown
Owner Author

pnpm test result and why the failures are the sandbox

Test Files  50 failed | 2130 passed (2181)
     Tests  55 failed | 20670 passed | 194 skipped (20919)

Failure causes, counted across the whole log:

62  Executable doesn't exist at /opt/pw-browsers/chromium_headless_shell-1228/...
55  Error: Chromium could not be launched
 3  Error: Port 63315 is in use, trying another one...
 3  Error: Chromium is required for the Lynx Web host smoke test
 1  Error: Test timed out in 5000ms.
 1  AssertionError: expected false to be true   (macOS Lynx Explorer native demo, on Linux)

This sandbox ships Chromium build 1194 (/opt/pw-browsers/chromium-1194) while
the installed Playwright pins 1228, so every browser project fails at launch
before running a line of test code. The same mismatch is why the lynx-table
harnesses in this PR call the shared chromiumLaunchOptions() helper, which
points at the image-provided binary — that is how the benchmark runs here at
all, and it is why stages/run.mjs now uses it too.

Two independent facts bound the blast radius:

  1. Every file in the commit is under benchmarks/lynx-table/
    (git diff --name-only HEAD~1 HEAD).
  2. vitest.config.js contains no reference to benchmarks/ — no vitest project
    includes that path.

So no vitest project can load anything this diff changes. The port-in-use and
5 s-timeout failures are contention artifacts of running the full suite on a
4-CPU box; packages/dropzone/tests/probes/hydration.test.ts fails the same way
when run alone here.

I could not run the browser suites on this machine, so the diff has not been
exercised against them — CI is the first place that happens.


Generated by Claude Code

@Huxpro Huxpro changed the title bench(lynx): attribute the FCP residual at the Element PAPI boundary perf(lynx): decompose the FCP residual at the Element PAPI boundary, and cut capture-time prop planning Aug 12, 2026
@github-actions github-actions Bot added the perf label Aug 12, 2026

Huxpro commented Aug 13, 2026

Copy link
Copy Markdown
Owner Author

Correction: the "public API" blocker was overstated, and the win is now landed

The PR body says deferring the first-tree description is blocked by two
contracts. On a closer look at the first one, that framing was too strong, and
re-examining the second changed the conclusion entirely. Commit 4b6c5796 lands
the deferral.

On firstScreenSnapshot(). It arrived on 2026-07-21 in d6ee6732
("Implement Lynx Milestone 6 first-screen adoption", #216), three weeks ago and
in a package that is four weeks old. @octanejs/lynx is private: true at
version 0.0.0 — not published — the accessor appears in no documentation, and
its only caller in the repository is first-screen.test.ts. It is reachable
through the ./main-thread export path, so it is not nothing, but "public API"
was the wrong weight to put on it. (My earlier reading of its introduction date
as 2026-08-08 was an artifact of a 163-commit shallow clone.)

It turned out not to need loosening. The second contract — a PAPI failure
during capture must fault render() — only pins the getUniqueId walk, and
that walk is the cheap part: ~16 ms of the ~290 ms window at 10k. Splitting
capture along validation-versus-allocation rather than eager-versus-lazy keeps
both contracts intact:

  • eager: structural validation, the native-ID read, the event token map (a tap
    on the painted tree resolves through it before adoption);
  • deferred: the clone-safe description, which reads only retained record fields
    and so still answers while unmount cleanup retries.

All 340 packages/lynx tests pass unchanged. Deliberately corrupting the
description turns 14 tests red across first-screen, host-driver, and
milestone-8-integration, so both read orders are already covered.

Measured, paired A/B with both bundles built side by side, alternating order,
n=8, 10,000-row first screen:

base with change paired median
post-publication window 217 ms 163 ms −54 ms, 8/8 pairs improved
FCP@10k 1,576 ms 1,483 ms −85 ms (−5.4%), 7/8 pairs improved

That is on top of the prop-planning skip in 978f3839. Unlike that commit, this
one is resolvable end to end on this host.


Generated by Claude Code

@Huxpro Huxpro changed the title perf(lynx): decompose the FCP residual at the Element PAPI boundary, and cut capture-time prop planning perf(lynx): decompose the FCP residual at the Element PAPI boundary, and take capture off the paint path Aug 13, 2026
@Huxpro
Huxpro force-pushed the claude/issue-50-39v4y1 branch from 4b6c579 to bbbbf3b Compare August 13, 2026 10:20
@Huxpro Huxpro changed the title perf(lynx): decompose the FCP residual at the Element PAPI boundary, and take capture off the paint path bench(lynx): attribute the FCP residual at the Element PAPI boundary Aug 13, 2026
@github-actions github-actions Bot removed the perf label Aug 13, 2026
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.

[lynx-perf-live 8] Instrument the ReactLynx reference with the same stage decomposition to attribute the FCP residual

1 participant