Skip to content

test(bench): size the first-screen prop memo before building it, and refute the cheap version - #264

Merged
Huxpro merged 2 commits into
new-lynxfrom
perf/lynx-first-screen-props-census
Aug 31, 2026
Merged

Huxpro merged 2 commits into
new-lynxfrom
perf/lynx-first-screen-props-census

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 31, 2026 •

Copy link
Copy Markdown
Owner

Summary

#247's bucket-4 attribution (#254, and the report on #247) names publish as the observed owner — 0.79 of the FCP gap at 10,000 rows, two-window spread 0.015 — and the function profile inside it puts cloneProps at 27.7 ms and planLynxHostPropPatch at 11.7 ms.

There is an obvious-looking cut there. The steady-state mount-template-run path already memoizes both the clone and the patch on the props object's identity (host-driver.ts:7323); the first-screen walk at host-driver.ts:5040 calls them unconditionally, per node, on the critical path to first paint. Two paths, same work, one of them already memoized.

This PR counts what pointing one at the other would buy, before anyone writes it. The answer is nothing.

Why

prepareStaticHostProps keys its memo on the props object's identity. At 10,000 rows the first-screen walk visits 60,028 host nodes, of which 40,028 are non-text — against 40,028 distinct props objects. The renderer allocates a fresh bag per node, so:

1,000 rows 10,000 rows
host nodes visited 6,028 60,028
memo-eligible 3,015 (50.0%) 30,015 (50.0%)
#text (excluded by design) 2,000 20,000
more than one key 1,013 10,013
not frozen / non-class key / non-string value 0 / 0 / 0 0 / 0 / 0
distinct props objects 4,028 40,028
→ identity-keyed memo hit rate 0.0000 0.0000
distinct (type, class) values 7 7
→ value-keyed memo hit rate 0.9977 0.9998

Adding the identity-keyed memo would cost a WeakMap lookup per node in order to miss every single time.

The same census says what would work, and it is a striking number: half of all first-screen hosts are already eligible on every other test — frozen, one key, that key class/className carrying a string, with zero misses for any other reason — and those 30,015 nodes resolve to 7 distinct (type, class) pairs. Seven, at both scales, because the class strings come from the template rather than from the data. The clone and the patch are both pure functions of that pair.

Whether to build the value-keyed version — the sizing argues no

Recorded here so the next reader does not have to re-derive it:

  • The class-only half are the cheapest clones in the bucket (one key, no recursion), so the addressable share of cloneProps's 27.7 ms + planLynxHostPropPatch's 11.7 ms is well under half of 39.4 ms.
  • Against a ±0.04 resolution on the FCP@10k ratio — about ±42 ms of Octane wall at this scale — a win of that size cannot be claimed from wall clock.
  • And it has no count oracle to fall back on, because it changes no host calls. fcp-attribution.md is explicit that counts are the reliable currency here and milliseconds are for sizing.

So the cut that can actually move bucket 4 past the line is the structural one — take record building off the critical path entirely (83.2 ms, the whole host record building bucket, built solely to feed captureLynxFirstTree) rather than shave the clone. That is #68.

Labelled: the sizing above is a bound, not a measurement of the candidate — no value-keyed memo was built or measured. The one effect it does not bound is allocation pressure: 30,015 object allocations and freezes replaced by 7 cache entries could have GC knock-on beyond the direct self time. That is a hypothesis, and it is the only argument left for building it.

Changes

  • stages/fs-props-census-source.mjs — build-time source patch that tallies, at the first-screen walk site, what prepareStaticHostProps would decide and why, plus distinct props objects and distinct (type, class) pairs. Same shape as stages/instrument-source.mjs: unambiguous anchors or it throws, and it restores the file after one build.
  • stages/fs-props-census-build.mjs — builds the census bundles (--universal, because the profiled cell is the universal octane one; the MTS-program cell paints its first screen from the compiled program and never enters this walk at all).
  • stages/results/c247-fsprops-census.json — the recorded tally at both scales, with the paint oracle beside each.

The second commit adds no measurement and changes no recorded value; it is gate repair, described under Validation.

Validation

  • the patch applies to a pristine new-lynx checkout and restores it to a clean tree
  • paint oracle passes at both scales alongside the census — 1,000 and 10,000 rows, classCount matching, checksums recorded
  • pnpm format:files:check on both authored files
  • pnpm sync — no generated changes
  • pnpm typecheck
  • pnpm test

This is a census, not an ablation: it changes no host call and no painted output, which is what the paint oracle beside each scale establishes. benchmarks/ is in no vitest.config.js project, so no test project reaches these files; the recorded tally is the result.

The format check above was scoped too narrowly, and the second commit is the repair. pnpm format:files:check ran on the two authored .mjs files, which is what that line claims and all it claims — it did not cover the third changed file, stages/results/c247-fsprops-census.json, which was hand-assembled and did not match what writeEvidenceJson emits. That record would therefore have failed Check formatting the moment this PR left draft, which is exactly the failure that turned new-lynx red earlier today and that #268 fixed for three other records. 600907136 rewrites it through the writer (72 lines reflowed, values untouched — the tally in the table above is unchanged), and takes two neighbours with it: bts-profile.mjs and papi-floor.mjs still wrote their records with a bare tab-indented JSON.stringify and now go through the writer too. It also gives fs-props-census-build.mjs the same --scales validation as #263's build script, so a typo'd or negative scale is refused rather than silently dropped into a partial arm.

Risk / follow-ups

  • The patch binds to textual anchors in host-driver.ts and throws on a miss rather than silently producing an uninstrumented bundle, but a reflow of the first-screen walk will need them re-fitted.
  • The census measures the lynx-table workload's row shape. The 50% eligible / 7 distinct pairs split is a property of that template, and an app with per-node inline styles or ids would land differently. The instrument is reusable; the numbers are this benchmark's.
  • CI is no longer wedged, and this line previously said it was. The runner pool recovered when ci: fall back to GitHub-hosted runners while the Blacksmith pool is stalled #260 merged its GitHub-hosted fallback at 14:12Z. On this head the draft-skipped set is green (typecheck, lint, apply labels); every heavy job reports skipped, which is what ci.yml does for a draft, not a failure. Nothing has yet run the heavy suite against this diff.
  • The write-site fix here covers bts-profile.mjs and papi-floor.mjs because they were adjacent, but nothing yet enforces that a stage probe writes through writeEvidenceJson. evidence.test.mjs checks the checked-in records, so it catches the drift after it lands rather than stopping a new probe from introducing it.

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

…refute the cheap version

#247's bucket-4 attribution puts publish at 0.79 of the FCP gap at 10,000 rows,
and the function profile inside it puts cloneProps at 27.7 ms and
planLynxHostPropPatch at 11.7 ms. The steady-state mount-template-run path
already memoizes both on the props object's identity through
prepareStaticHostProps; the first-screen walk at host-driver.ts:5040 calls them
unconditionally per node. Pointing one at the other is the cheapest-looking cut
in the attribution, so this counts what it would actually buy before anyone
writes it.

It buys nothing, and the census says so exactly rather than approximately. At
10,000 rows the first-screen walk visits 60,028 host nodes and 40,028 of them
are non-text -- against 40,028 distinct props objects. The renderer allocates a
fresh bag per node, so an identity-keyed memo has a hit rate of 0.0000 and
adding one would cost a WeakMap lookup per node to miss every time.

The same census says what would work. Half of all first-screen hosts (30,015,
50.0% at both scales) are already memo-eligible on every other test -- frozen,
one key, that key class or className carrying a string, with zero misses for any
other reason -- and those 30,015 nodes resolve to 7 distinct (type, class)
pairs. Seven, at 1,000 rows and at 10,000 alike, because the class strings come
from the template rather than from the data. A value-keyed memo hits 0.9998.

Whether that is worth building is a separate question this does not answer, and
the sizing argues no: the class-only half are the cheapest clones in the bucket,
so the addressable share of those 39.4 ms is well under half of it, against a
+/-0.04 resolution that is about +/-42 ms of wall at this scale. The cut has no
host-call count oracle either, because it changes no host calls.

The census is a tally, not an ablation: it changes no host call and no painted
output, and the paint oracle recorded beside each scale is the evidence of that.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
Three gate items of one class:
- the checked-in census record was hand-assembled and prettier-red;
  rewritten through writeEvidenceJson, values untouched.
- the census build CLI silently dropped a typo'd --scales entry and
  accepted a negative one; parses before filtering and refuses both.
- bts-profile and papi-floor still wrote records with a bare tab
  stringify — the same latent defect #268 fixed in heap-retention;
  both now write through the evidence writer.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YHfFsy9CLaRovTFH8pTGyY
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.

2 participants