Repository navigation
Description
What this is
Every emission decision in the #163 train so far has been settled by buying a measurement window: emit unrolled straight-line code, then A/B it when a number looks wrong (C7/C8's append order; #194 Q2's scaling curve). That works, but it prices one decision per window and predicts nothing. This issue builds the thing that makes the next ten decisions calculable: a measured cost model of the LepusNG interpreter — what a JIT-less VM actually charges for, per primitive.
#194 Q2 (code-staging vs data-staging at 1k/10k/30k) is one slice of this model. This issue generalizes it. Report, records, and a small derived table — no production code.
M1 — The primitive cost table
Microbenchmarks on device, each isolating one primitive the emitted code is built from, with per-op cost derived from a scaling series (not a single point):
- Dispatch & calls: empty-loop iteration cost; function call overhead (0/3/8 args); call through a local binding vs a property load (
f()vso.f()); the cost of crossing into a host/PAPI function vs a Lepus-defined one. - Property & environment access: local read vs closure read vs global read; monomorphic property load/store; array index read/write; how cost changes with object shape count at the site (1/2/8 shapes).
- Allocation & strings: object literal, array literal, closure creation; string concat vs template; the cost of a string that crosses to a host call vs one that stays in Lepus.
- Branching:
ifchains vsswitchvs computed dispatch (table of functions) at 4/16/64 arms — this directly prices the update wire's slot dispatch and Future: compiled main-thread programs inside native list rows — and whether the list API itself is the right surface #193's shape-class dispatch. - Each measured at n≥5 with the Device measurement round 1: the four questions the web windows cannot answer (#163 clause 4) #194 protocol (DevTool off, AB/BA, load control), reported as ns/op with the fit and residual, plus the same suite run once on V8 (web) so every row has a "JIT would have hidden this" column.
M2 — Validate the model against the decisions we already paid for
A model that cannot postdict the windows we already bought is not a model:
- Recompute, from M1's table alone, the predicted script self-time of the emitted program at 1k/10k/30k, and compare against Device measurement round 1: the four questions the web windows cannot answer (#163 clause 4) #194 Q2's measured curve.
- Predict the cost delta of the C8 append-order variants from the model's primitives (it should predict ~0 for script — the C7 finding was flush-side — and saying so is the test).
- Target: within 25% on absolute, correct ordering on every pair. Report where it misses; the misses are the interesting part.
M3 — The derived emission guide
The deliverable that outlives the windows: a short table mapping emitter choices to model-predicted costs, each row marked calculated / validated / refuted:
- Unrolled create vs per-shape function + tight loop, as a function of node count and shape count (feeds Future: compiled main-thread programs inside native list rows — and whether the list API itself is the right surface #193 R3 and the Device measurement round 1: the four questions the web windows cannot answer (#163 clause 4) #194 Q2 decision).
- Slot-dispatch shape for the update wire: if/switch/table, at realistic slot counts.
- String handling for text holes: concat-at-emit vs pass-through, given M1's string rows.
- Whether property-access caching (hoisting
papi.createElementto a local, etc.) is worth emitting — the model should price it exactly.
Protocol and scope
Device measurement per #194's protocol section; check records into benchmarks/lynx-table/stages/results/ one file per window; name the LepusNG/engine version in every record — the model is version-stamped, and re-validation on engine upgrades is expected, not a failure. Web (V8) columns are context only and never spendable on device decisions. Ordering: M1 dispatch+property rows first — they dominate every downstream prediction; strings and branching after; M2 before any M3 row is marked validated.
Activity
Huxpro commentedon Aug 26, 2026
LepusNG cost-model report — Aries 10 / LepusNG 2.3.0
Implementation and checked-in evidence: draft PR #207. The full report and derived JSON model carry the engine stamp and SHA-256 provenance for every input.
Verdict
M1 completed, but M2 closed the validation gate. The frozen 1k Q2 emitted-program prediction was 7.757 ms; the protocol-valid device median was 150 ms, a 94.83% relative absolute error against the ≤25% target. The ordering prediction was correct (program faster than interpreted template), but the absolute model is refuted. Therefore no M3 row is marked validated.
147,150,162,146,162341,338,337,339,332M1 primitive rows
All device rows use n=5 AB/BA paired deltas at four iteration counts. Positive is candidate minus control.
V8 was recorded as context-only; its host globals are JS mocks and none of its values feed device decisions or M2.
Boundary and attribution
The valid 1k program window executes the real emitted program against an M1-matched crossing surrogate: numeric factory/append calls use
getUniqueId, string calls usesetAttributeon one detached sentinel, and no per-call clock is read. The template boundary ends after outerrenderPlanNodeand before paint. Both arms log and then throw a terminal sentinel, excluding paint/flush.Parse/eval is not observable with DevTool disabled because native evaluates bytecode before an in-bundle clock can start; launch wall mixes native load/layout and is not substituted. The frozen inventory also assumed 20 whole-cell crossings/row, while the emitted row-shaped program exposed 15.121 surrogate crossings/row and 5,041 program nodes at 1k. I did not revise the frozen prediction after seeing this miss.
M3 guide (gate closed)
Protocol notes: DevTool disabled; n=5; AB/BA; full samples and medians retained; pre/post load, thermal, and battery recorded; each window has its own file; invalid attempts are non-spendable and never aggregated. Device stamp:
aries_10, Android 10, arm64-v8a; LepusNG 2.3.0; app-bundle engine 3.9; Lynx SDK 4.0.Validation: all 5 targeted Node test files pass, all harness files pass
node --check, targeted Prettier passes,pnpm syncpasses, and all frozen/report hashes plus the M2→M3 gate were reverified. Fullpnpm testcould not start because dependency preparation exhausted host disk space (ENOSPC); no test assertion failed.