Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(bench): the hit publication is witnessed by an instrument that contains it

esengine36f33d091d92
diff --git a/bench/residency/README.md b/bench/residency/README.md
index f775017bd..990e2779c 100644
--- a/bench/residency/README.md
+++ b/bench/residency/README.md
@@ -530,11 +530,7 @@ thread was afterwards instead: on the miss arm that reported 52.5 ms for the sam
Two things this remeasure does not settle, both older than it:
-- `hit`'s publication is witnessed by one instrument. The cross-check reads the
- frame profiler's `scene` domain, which carries 0.1 ms there against 7.5 ms of
- named phases, so the hit arm exits non-zero on that check and on that check
- alone. Publication on a hit lands in the residency system's own timer, not in
- `scene`; the witness has not been moved.
+- `hit`'s publication was witnessed by one instrument. Closed below.
- `miss`'s `issue → prepared` is latency, not CPU, and varies 22–65 ms with what
the fetch and the frame queue do. The named phases account for it when nothing
stalls; a stalled run leaves the stall unnamed, which is what it is.
@@ -545,6 +541,41 @@ frame into the publication transaction would not be a fix either — a hitch
relocated is still a hitch. The numbers above are what makes that a settled
question rather than a principle: publication did not move.
+#### Publication witness closure
+
+The HIT arm's cross-check read the frame profiler's `scene` domain and found
+0.03–0.2 ms against 7 ms of named phases. Three instruments, and it took all
+three to see why:
+
+| instrument | what it covers | on a hit |
+| --- | --- | --- |
+| named publication phases | the transaction body, wherever it runs | 7.2–13.7 ms |
+| the demand frame's wall that no system claimed | the same body, from the frame's side | 6.7–12.7 ms |
+| `scene` domain (`WorldResidencySystem`) | what ran INSIDE the system function | 0.03–0.2 ms |
+| `publish → resident` wall | the streamer's clock, which spans the rest of the frame | 10.6 ms |
+
+`step_` runs synchronously out of `WorldResidencySystem` only as far as
+`loadAdditive`'s first await. Everything after that — which is the transaction —
+is microtask continuations: inside the frame, after the system function returned.
+So no SYSTEM timer contains it, and the domain that names the system is not a
+witness for the work. It was not the wrong domain; it was the wrong kind of
+instrument.
+
+The frame it lands in is the DEMAND frame, the first one recorded — the launcher
+sends the keydown before the loop. `publishAt` is where the resident flag flips,
+which on this path is the frame after the work. Witnessing across the realization
+window therefore missed the publication frame as well.
+
+Witnessed by the demand frame's unclaimed wall, the two instruments agree to
+107.9–111.3% across three runs and track each other run to run. The `scene`
+number is still printed, beside it, as what it is.
+
+One flake is left, and it is not this: `and so is the preparation prefetch hides`
+allows a fixed 0.6 ms of unnamed preparation, and the residual grows with the
+number of await hops a preparation makes — 0.5 ms at `prepareMs` 20–34, 0.9 ms at
+40.6. The sibling per-frame budget is proportional for exactly this reason and
+this one is not. Left as measured rather than widened here.
+
#### What MISS now means, which is not what it meant
A miss used to be the arm without the headroom: nothing readied it early, so the
diff --git a/bench/residency/heavy.mjs b/bench/residency/heavy.mjs
index 9a83c78fa..77768438c 100755
--- a/bench/residency/heavy.mjs
+++ b/bench/residency/heavy.mjs
@@ -405,10 +405,17 @@ function report(arm, frames, delivery) {
`peak render.mesh.programCompiles ${compiledInWindow} in the window,`
+ ` ${compiledInRun} across the run`);
- // Which clock brackets the publication transaction depends on where it runs:
- // between frames the streamer's wall time does; inside the frame that spans
- // the rest of it, and only the profiler's `scene` domain is left.
- const sceneExcess = window.reduce((a, f) => a + (byDomain(f).get('scene') ?? 0), 0)
+ // No SYSTEM timer brackets a hit's publication: `step_` leaves the residency
+ // system at `loadAdditive`'s first await. The demand frame's unclaimed wall
+ // does — frames[0]; `publishAt` is the flag flipping, a frame later.
+ const demandFrame = frames[0];
+ const claimedByNoSystem = demandFrame
+ ? Math.max(0, demandFrame.ms - sumDomains(demandFrame))
+ : 0;
+ // Reported beside it, never as it: this is what ran INSIDE the residency
+ // system — deciding and starting the load — and it is 0.1 ms against a 7 ms
+ // transaction. Witnessing publication with it was witnessing another domain.
+ const residencySystem = window.reduce((a, f) => a + (byDomain(f).get('scene') ?? 0), 0)
- (baselineDomains.get('scene') ?? 0) * window.length;
for (const [cell, v] of Object.entries(delivery ?? {})) {
@@ -430,7 +437,7 @@ function report(arm, frames, delivery) {
// inside the frame that asked, so wall time there spans the whole frame.
// Keying it on the arm made a third hitting arm read the wrong clock.
const witness = v.outcome === 'hit'
- ? { ms: sceneExcess, what: "the frame profiler's `scene` domain" }
+ ? { ms: claimedByNoSystem, what: "the demand frame's wall that no system claimed" }
: { ms: v.publishMs, what: 'publish → resident wall time' };
console.log(` ${'= accounted'.padEnd(22)}${published.toFixed(2).padStart(7)} ms`);
console.log(` ${'against'.padEnd(22)}${witness.ms.toFixed(2).padStart(7)} ms`
@@ -438,6 +445,9 @@ function report(arm, frames, delivery) {
if (v.outcome === 'hit') {
console.log(` ${'(publish → resident'.padEnd(22)}${v.publishMs.toFixed(2).padStart(7)} ms`
+ ` wall, which on a hit spans the whole frame — not the transaction.)`);
+ console.log(` ${'(WorldResidencySystem'.padEnd(22)}${residencySystem.toFixed(2).padStart(7)} ms`
+ + ' the `scene` domain: what ran inside the system, which is the'
+ + ' decision and the start of the load — not the transaction.)');
}
console.log(`\n ${'delivery'.padEnd(22)}${v.deliveryMs.toFixed(2).padStart(7)} ms issue → resident`);