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.

feat(bench): two ways into one cell, because prefetch moves the cost rather than removing it

esengine4dccaa975b4d
diff --git a/bench/residency/heavy.mjs b/bench/residency/heavy.mjs
index 3a0cca3f7..ef757d071 100755
--- a/bench/residency/heavy.mjs
+++ b/bench/residency/heavy.mjs
@@ -137,14 +137,18 @@ import type { World, InputState } from 'esengine';
const radiusSystem = defineSystem(
[Res(Input), GetWorld()],
(input: InputState, world: World) => {
- const on = input.isKeyPressed('Digit1');
- if (!on && !input.isKeyPressed('Digit0')) return;
+ // Digit2 readies without wanting; Digit1 wants. Pressed in that order the
+ // arrival is a HIT, and pressing Digit1 alone is the miss.
+ const ready = input.isKeyPressed('Digit2');
+ const want = input.isKeyPressed('Digit1');
+ if (!ready && !want) return;
const source = world.findEntityByName('Source');
if (source === null) return;
world.update(source, WorldStreamingSource, (s) => {
- s.loadRadius = on ? 3000 : 0;
- s.unloadRadius = on ? 3200 : 0;
- s.enabled = on;
+ s.loadRadius = want ? 3000 : 0;
+ s.prefetchRadius = ready ? 3000 : 0;
+ s.unloadRadius = 3200;
+ s.enabled = true;
});
},
{ name: 'RadiusSystem' },
@@ -180,13 +184,40 @@ function main() {
process.exit(1);
}
- const script = path.join(WORK, 'probe.json');
- writeFileSync(script, JSON.stringify([
- { do: 'step', frames: 30 },
- // One frame at a time from the gesture, so the arrival is a row and not
- // an average, with a system breakdown wherever a frame is expensive.
- { do: 'frames', as: 'arrival', key: 'Digit1', count: 240, costsAbove: 1.0 },
- ], null, 2));
+ // Two ways into the SAME cell, each from a cold cache, because the question
+ // "what does prefetch cost" has no answer from one of them: readying early
+ // does not make the work cheaper, it moves WHEN it is paid.
+ const arms = [
+ ['miss', [
+ { do: 'step', frames: 30 },
+ // One frame at a time, every one broken down: an arrival costs its
+ // excess over a steady state, and a steady state nobody broke down is
+ // a number to subtract from rather than one to attribute.
+ { do: 'frames', as: 'arrival', key: 'Digit1', count: 240, costsAbove: 0 },
+ ]],
+ ['hit', [
+ { do: 'step', frames: 30 },
+ // Readied and SETTLED first: `arrive` waits out `preparing`, so the
+ // demand below meets a cell that is already `prepared`.
+ { do: 'arrive', as: 'primed', key: 'Digit2' },
+ { do: 'frames', as: 'arrival', key: 'Digit1', count: 240, costsAbove: 0 },
+ ]],
+ ];
+
+ for (const [arm, steps] of arms) {
+ const { frames, delivery } = drive(out, arm, steps);
+ report(arm, frames, delivery);
+ }
+ console.log('');
+ process.exit(failedTotal === 0 ? 0 : 1);
+}
+
+let failedTotal = 0;
+
+/** Run one arm in its own Electron, so each pays for its own cold cache. */
+function drive(out, name, steps) {
+ const script = path.join(WORK, `${name}.json`);
+ writeFileSync(script, JSON.stringify(steps, null, 2));
const run = runElectron([LAUNCHER, '--dir', out, '--script', script, '--w', '640', '--h', '360'],
{ encoding: 'utf8', cwd: ROOT });
@@ -197,50 +228,294 @@ function main() {
const kind = line.slice(at, line.indexOf(' ', at));
try { readings[kind] = JSON.parse(line.slice(line.indexOf(line.includes('profile') && kind === 'profile' ? '[' : '{', at))); } catch { /* partial */ }
}
- const frames = readings.profile;
- const delivery = readings.delivery;
- if (!frames) {
- console.error(`✗ nothing was measured — ${(run.stdout || run.stderr || '').slice(-500)}`);
- process.exit(1);
+ if (!readings.profile) {
+ console.error(`✗ ${name}: nothing was measured — ${(run.stdout || run.stderr || '').slice(-500)}`);
+ process.exit(2);
+ }
+ return { frames: readings.profile, delivery: readings.delivery };
+}
+
+function report(arm, frames, delivery) {
+
+ console.log(`\n${'='.repeat(78)}\nheavy cell, ${arm.toUpperCase()} — `
+ + `${arm === 'hit' ? 'readied before it was wanted' : 'wanted before anything readied it'}`
+ + ` — 1 skin, ${PROPS} imported props, ${BODIES} bodies\n`);
+
+ let failed = 0;
+ const check = (ok, claim, detail) => {
+ if (!ok) failed++;
+ failedTotal += ok ? 0 : 1;
+ console.log(` ${ok ? '✓' : '✗'} ${claim}${detail ? ` — ${detail}` : ''}`);
+ };
+
+ // Index 0 included: both arms begin with nothing resident, and the hit path
+ // publishes inside the frame that asked — a finder skipping frame 0 cannot
+ // see the one arrival prefetch exists to produce.
+ const arrivalAt = frames.findIndex((f) => f.resident > 0);
+ // MEANS, and means for both halves. A median wall time against mean domain
+ // times is two baselines, and the excess arithmetic below then does not
+ // close — it reported 112% of an excess it had mis-subtracted.
+ const settled = frames.slice(-60);
+ const mean = (values) => values.reduce((a, b) => a + b, 0) / (values.length || 1);
+ const baseline = mean(settled.map((f) => f.ms));
+ const baselineSystems = mean(settled.map((f) => sumDomains(f)));
+ const baselineDomains = new Map();
+ for (const f of settled) {
+ for (const [domain, ms] of byDomain(f)) {
+ baselineDomains.set(domain, (baselineDomains.get(domain) ?? 0) + ms / settled.length);
+ }
+ }
+ // Closes on quiet, not on a count. Realization lands a variable number of
+ // frames after publication, so a fixed window is one that sometimes misses
+ // the thing it exists to measure.
+ const QUIET = 3;
+ const window = [];
+ if (arrivalAt >= 0) {
+ let calm = 0;
+ for (let i = arrivalAt; i < frames.length && window.length < 40; i++) {
+ window.push(frames[i]);
+ calm = frames[i].ms <= baseline + 0.3 ? calm + 1 : 0;
+ if (calm >= QUIET) break;
+ }
}
- const heavy = frames.filter((f) => f.ms > 1.0);
- const arrival = frames.find((f, i) => i > 0 && frames[i - 1].resident === 0 && f.resident > 0);
- console.log(`\nheavy cell — 1 skin, ${PROPS} imported props, ${BODIES} bodies\n`);
- // Which HALF a phase belongs to is what decides whether prefetch can hide
- // it: `prepare()` can run before a player wants the place, and `spawn` is
- // paid at the door however early the readying happened.
- const PREPARATION = new Set(['fetch', 'prefab', 'assets']);
+ // 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)
+ - (baselineDomains.get('scene') ?? 0) * window.length;
+
for (const [cell, v] of Object.entries(delivery ?? {})) {
- const phases = Object.entries(v.phases).sort((a, b) => b[1] - a[1]);
- const total = (keep) => phases.filter(([p]) => PREPARATION.has(p) === keep)
- .reduce((sum, [, ms]) => sum + ms, 0);
+ const roots = tree(v.phases);
+ const half = (keep) => roots.filter((n) => PREPARATION.has(n.name) === keep);
+
+ console.log(` ${cell} — where its delivery went\n`);
console.log(' preparation — between frames, on no system timer, and hideable:');
- for (const [phase, ms] of phases) {
- if (PREPARATION.has(phase)) console.log(` ${phase.padEnd(8)} ${ms.toFixed(2).padStart(8)} ms`);
+ printTree(half(true), ' ');
+ const prepared = sum(half(true));
+ console.log(` ${'= accounted'.padEnd(22)}${prepared.toFixed(2).padStart(7)} ms`
+ + ` of ${v.prepareMs.toFixed(2)} ms issue → prepared (${pct(prepared, v.prepareMs)})`);
+
+ console.log('\n publicationCost — the publication transaction: prepared data → ECS-visible.');
+ console.log(' What demand pays whatever prefetch did, and it is NOT all of what demand pays:');
+ printTree(half(false), ' ');
+ const published = sum(half(false));
+ const witness = arm === 'hit'
+ ? { ms: sceneExcess, what: "the frame profiler's `scene` domain" }
+ : { 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`
+ + ` from ${witness.what} (${pct(published, witness.ms)})`);
+ if (arm === '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(` ${'= total'.padEnd(8)} ${total(true).toFixed(2).padStart(8)} ms`);
- console.log('\n publication — what demand pays whatever prefetch did:');
- for (const [phase, ms] of phases) {
- if (!PREPARATION.has(phase)) console.log(` ${phase.padEnd(8)} ${ms.toFixed(2).padStart(8)} ms`);
+ console.log(`\n ${'delivery'.padEnd(22)}${v.deliveryMs.toFixed(2).padStart(7)} ms issue → resident`);
+
+ // Two instruments on one interval, so either being wrong shows up as
+ // disagreement. A one-sided check would pass by over-counting.
+ check(published >= witness.ms * 0.9 && published <= witness.ms * 1.15,
+ 'the publication a player pays for is explained by named work',
+ `${published.toFixed(2)} ms of named phases against ${witness.ms.toFixed(2)} ms `
+ + `from ${witness.what} (${pct(published, witness.ms)})`);
+ // The check above is satisfied by `spawn: 6.8 ms` and nothing else —
+ // the state this bench was written to leave. A total is not a mechanism.
+ const biggest = leaves(half(false)).sort((a, b) => b.ms - a.ms)[0] ?? { name: 'none', ms: 0 };
+ check(biggest.ms <= published * 0.5,
+ 'and no single undivided phase is most of it — a total would be, a mechanism is not',
+ `largest is ${biggest.name} at ${pct(biggest.ms, published)} of publication`);
+ const deepest = closure(half(false));
+ if (deepest) {
+ console.log(` (the instrument closes to ${(deepest.ratio * 100).toFixed(1)}% at its worst `
+ + `parent, ${deepest.name} — reported, not a criterion: sub-phases partition their `
+ + `parent by construction.)`);
}
- console.log(` ${'= total'.padEnd(8)} ${total(false).toFixed(2).padStart(8)} ms`);
- console.log(`\n ${'delivery'.padEnd(8)} ${v.deliveryMs.toFixed(2).padStart(8)} ms (issue → resident, ${cell})`);
- }
- console.log('\n the frames it cost, by system:');
- for (const f of heavy.slice(0, 12)) {
- const at = frames.indexOf(f);
- const rows = f.costs?.systems ?? [];
- const top = f.costs && !f.costs.on ? 'stats never engaged'
- : rows.slice(0, 4).map((c) => `${c.name} ${c.ms.toFixed(2)}`).join(', ');
- console.log(` f${String(at).padEnd(4)} ${f.ms.toFixed(2).padStart(6)} ms ent=${f.entities} bodies=${f.bodies}${top ? ` | ${top}` : ''}`);
- }
- const worst = Math.max(...frames.map((f) => f.ms));
- const phases = Object.values(delivery ?? {})[0]?.phases ?? {};
- const largest = Object.entries(phases).sort((a, b) => b[1] - a[1])[0] ?? ['none', 0];
- console.log(`\n largest single frame ${worst.toFixed(1)} ms; largest atomic phase `
- + `${largest[0]} ${largest[1].toFixed(1)} ms`);
- console.log(` arrival landed on frame ${arrival ? frames.indexOf(arrival) : '(none)'}\n`);
+ check(prepared >= v.prepareMs * 0.95,
+ 'and so is the preparation prefetch hides',
+ `${pct(prepared, v.prepareMs)} of ${v.prepareMs.toFixed(2)} ms accounted`);
+ }
+
+ console.log(`\n realization — ECS-visible → actually drawn. Steady state ${baseline.toFixed(2)} ms/frame, `
+ + `the cell became visible on frame ${arrivalAt < 0 ? '(none)' : arrivalAt}\n`);
+ console.log(' frame wall systems accounted | by domain');
+ for (const f of window) {
+ const domains = byDomain(f);
+ const accounted = [...domains.values()].reduce((a, b) => a + b, 0);
+ const top = [...domains].sort((a, b) => b[1] - a[1]).filter(([, ms]) => ms >= 0.01).slice(0, 4)
+ .map(([d, ms]) => `${d} ${ms.toFixed(2)}`).join(', ');
+ console.log(` f${String(frames.indexOf(f)).padEnd(6)}${f.ms.toFixed(2).padStart(7)}`
+ + `${accounted.toFixed(2).padStart(9)}${pct(accounted, f.ms).padStart(10)} | ${top}`);
+ }
+ const wall = window.reduce((a, f) => a + f.ms, 0);
+ const accounted = window.reduce((a, f) => a + sumDomains(f), 0);
+ console.log(` ${'window'.padEnd(7)}${wall.toFixed(2).padStart(7)}${accounted.toFixed(2).padStart(9)}`
+ + `${pct(accounted, wall).padStart(10)}`);
+ // Every frame costs something outside every system (the step call, the
+ // promise turn). Charged to the arrival it makes the ratio a measure of how
+ // CHEAP the window was, so excess is judged against excess.
+ const wallExcess = wall - baseline * window.length;
+ const systemExcess = accounted - baselineSystems * window.length;
+
+ // What the arrival ADDED, which is the only part of these frames residency
+ // is answerable for: the same systems run on every other frame too.
+ const excess = wallExcess;
+ const perDomain = new Map();
+ for (const f of window) {
+ for (const [domain, ms] of byDomain(f)) perDomain.set(domain, (perDomain.get(domain) ?? 0) + ms);
+ }
+ for (const [domain, ms] of baselineDomains) {
+ perDomain.set(domain, (perDomain.get(domain) ?? 0) - ms * window.length);
+ }
+ console.log(`\n the arrival cost these ${window.length} frames ${excess.toFixed(2)} ms above steady state:`);
+ for (const [domain, ms] of [...perDomain].sort((a, b) => b[1] - a[1])) {
+ if (Math.abs(ms) < 0.05) continue;
+ console.log(` ${domain.padEnd(16)}${ms.toFixed(2).padStart(7)} ms`);
+ }
+
+ console.log('');
+ check(window.length > 0 && systemExcess >= wallExcess * 0.95,
+ 'and what the arrival ADDS to those frames is explained by the systems that ran',
+ `${pct(systemExcess, wallExcess)} of ${wallExcess.toFixed(2)} ms of excess over `
+ + `${window.length} frames (raw: ${pct(accounted, wall)} of ${wall.toFixed(2)} ms, `
+ + `which carries ${((baseline - baselineSystems) * window.length).toFixed(2)} ms of `
+ + `per-frame overhead outside every system)`);
+
+ const first = Object.values(delivery ?? {})[0];
+ const publicationCost = first
+ ? sum(tree(first.phases).filter((n) => !PREPARATION.has(n.name)))
+ : 0;
+ const firstVisibleFrameCost = window.length ? Math.max(...window.map((f) => f.ms)) : 0;
+ const arrivalWindowCost = excess;
+ console.log(`\n what one heavy arrival costs the main thread:\n`);
+ console.log(` publicationCost ${publicationCost.toFixed(2).padStart(6)} ms prepared data → ECS-visible, between frames`);
+ console.log(` firstVisibleFrameCost ${firstVisibleFrameCost.toFixed(2).padStart(6)} ms the dearest single frame of the arrival`);
+ console.log(` arrivalWindowCost ${arrivalWindowCost.toFixed(2).padStart(6)} ms ${window.length} frames, above steady state`);
+ console.log(` ${'─'.repeat(60)}`);
+ console.log(` ECS publication finishing is not the delivery paid for: the larger`);
+ console.log(` half lands after it, in realization.\n`);
+
+ // A budget line, not a tolerance: an arrival may have half a 60 Hz frame
+ // because the GAME needs the other half. This fixture's world is nearly
+ // empty, so a pass says nothing about a real one and a fail says everything.
+ const HEADROOM = 1000 / 60 / 2;
+ const spike = firstVisibleFrameCost - baseline;
+ const fits = spike <= HEADROOM;
+ console.log(` ${fits ? '✓' : '✗'} BUDGET — a heavy arrival leaves the game its half of the frame`
+ + ` — ${spike.toFixed(2)} ms of arrival work against ${HEADROOM.toFixed(2)} ms of headroom`);
+ if (!fits) failed++;
+
+ void failed;
+ const worstAt = frames.reduce((best, f, i) => (f.ms > frames[best].ms ? i : best), 0);
+ const worst = frames[worstAt];
+ console.log(`\n largest single frame of the whole run: f${worstAt} at ${worst.ms.toFixed(1)} ms`
+ + ` — ${[...byDomain(worst)].sort((a, b) => b[1] - a[1]).filter(([, ms]) => ms >= 0.05).slice(0, 4)
+ .map(([d, ms]) => `${d} ${ms.toFixed(2)}`).join(', ') || 'no breakdown'}`
+ + `${worstAt >= arrivalAt && worstAt < arrivalAt + window.length ? ' (inside the arrival window)'
+ : ' (OUTSIDE the arrival window)'}`);
+}
+
+/**
+ * A cell's phases, as the tree their dotted names describe.
+ *
+ * `spawn.components.MeshRenderer` is inside `spawn.components` is inside
+ * `spawn`, so the roots are the only rows that may be summed — adding the whole
+ * flat list counts the same milliseconds three times.
+ */
+function tree(phases) {
+ const nodes = new Map();
+ const node = (name) => {
+ let n = nodes.get(name);
+ if (!n) { n = { name, ms: 0, children: [] }; nodes.set(name, n); }
+ return n;
+ };
+ for (const [name, ms] of Object.entries(phases)) node(name).ms = ms;
+ const roots = [];
+ for (const [name, n] of nodes) {
+ const cut = name.lastIndexOf('.');
+ if (cut < 0) roots.push(n);
+ else node(name.slice(0, cut)).children.push(n);
+ }
+ const order = (list) => {
+ list.sort((a, b) => b.ms - a.ms);
+ for (const n of list) order(n.children);
+ };
+ order(roots);
+ return roots;
+}
+
+const sum = (nodes) => nodes.reduce((total, n) => total + n.ms, 0);
+
+/** Every phase with no breakdown of its own — the rows a total could hide in. */
+function leaves(nodes) {
+ const out = [];
+ const walk = (list) => {
+ for (const n of list) {
+ if (n.children.length === 0) out.push(n);
+ else walk(n.children);
+ }
+ };
+ walk(nodes);
+ return out;
+}
+
+/**
+ * The worst parent at explaining itself. Summing the ROOTS is blind to a `spawn`
+ * measured as one number: its root sum is perfect and it explains nothing.
+ */
+function closure(nodes) {
+ let worst = null;
+ const walk = (list) => {
+ for (const n of list) {
+ if (n.children.length > 0 && n.ms > 0.05) {
+ const ratio = sum(n.children) / n.ms;
+ if (worst === null || ratio < worst.ratio) worst = { name: n.name, ratio, ms: n.ms };
+ }
+ walk(n.children);
+ }
+ };
+ walk(nodes);
+ return worst;
+}
+
+
+/** Print one phase subtree, naming what its children do not explain. */
+function printTree(nodes, indent) {
+ for (const n of nodes) {
+ const leaf = n.name.slice(n.name.lastIndexOf('.') + 1);
+ console.log(`${indent}${leaf.padEnd(26 - indent.length)}${n.ms.toFixed(2).padStart(7)} ms`);
+ if (n.children.length === 0) continue;
+ printTree(n.children, indent + ' ');
+ // A parent measured by one clock against children measured by another:
+ // the gap is real work nobody named, and hiding it would make every
+ // accounting below true by construction.
+ const rest = n.ms - sum(n.children);
+ if (rest > 0.005) {
+ console.log(`${indent} ${'(unattributed)'.padEnd(24 - indent.length)}${rest.toFixed(2).padStart(7)} ms`);
+ }
+ }
+}
+
+/** Which half of delivery owns a root phase — the split prefetch turns on. */
+const PREPARATION = new Set(['fetch', 'prefab', 'assets', 'discover', 'subsystems']);
+
+
+const pct = (part, whole) => (whole > 0 ? `${((part / whole) * 100).toFixed(1)}%` : '—');
+const median = (values) => {
+ if (values.length === 0) return NaN;
+ const sorted = [...values].sort((a, b) => a - b);
+ return sorted[Math.floor(sorted.length / 2)];
+};
+
+/** What one frame cost, by the domain that owns each system. */
+function byDomain(frame) {
+ return new Map(Object.entries(frame.domains ?? {}));
+}
+
+/** What this frame's systems cost in total — the attributed half of its wall time. */
+function sumDomains(frame) {
+ let total = 0;
+ for (const ms of Object.values(frame.domains ?? {})) total += ms;
+ return total;
}
main();
diff --git a/bench/residency/prefetch.mjs b/bench/residency/prefetch.mjs
index 737e202c3..4ec2e8304 100644
--- a/bench/residency/prefetch.mjs
+++ b/bench/residency/prefetch.mjs
@@ -240,6 +240,35 @@ function arrivals(streaming) {
return rows.sort((a, b) => Number(a.cell.match(/\d+/g).at(-2)) - Number(b.cell.match(/\d+/g).at(-2)));
}
+/**
+ * What a cell that is READY but not published can be seen to own.
+ *
+ * Asked of the world's own totals, not of the streamer's report of itself: an
+ * entity belonging to no resident cell is one a preparation leaked, whatever
+ * the streamer says about it.
+ */
+function unpublished(streaming) {
+ const prepared = streaming.preparedCells ?? [];
+ const entityRows = streaming.cellEntityCounts ?? {};
+ const renderRows = streaming.cellRenderCounts ?? {};
+ const inCells = Object.values(entityRows).reduce((a, b) => a + b, 0);
+ return {
+ prepared,
+ resident: streaming.residentCells.length,
+ entities: streaming.entities,
+ persistent: streaming.persistentEntities,
+ inCells,
+ bodies: streaming.physicsBodies,
+ named: prepared.filter((c) => c in entityRows || c in renderRows),
+ // Persistent world + every resident cell should be the whole population.
+ unowned: streaming.entities - streaming.persistentEntities - inCells,
+ // The fixture puts bodies in cells and none in the persistent world, so
+ // the solver's population is a count of published cells and nothing else.
+ strayBodies: streaming.physicsBodies - streaming.residentCells.length * BODIES,
+ stalePhysics: streaming.stalePhysics ?? 0,
+ };
+}
+
function summarise(streaming) {
const rows = arrivals(streaming);
const latency = rows.map((r) => r.latency);
@@ -262,6 +291,7 @@ function summarise(streaming) {
fetch: percentile(rows.map((r) => r.fetch), 0.5),
assets: percentile(rows.map((r) => r.assets), 0.5),
spawn: percentile(rows.map((r) => r.spawn), 0.5),
+ unpublished: unpublished(streaming),
};
}
@@ -347,6 +377,20 @@ function main() {
+ ` → the player waited ${ms(r.latency)} ms`);
}
+ console.log('\n what a readied-but-unpublished cell owns, when the walk ends:');
+ console.log(' scenario prepared resident entities persistent in cells unowned'
+ + ' bodies stray');
+ for (const [name, s] of measured) {
+ const u = s.unpublished;
+ console.log(` ${name.padEnd(13)} ${String(u.prepared.length).padStart(8)}`
+ + ` ${String(u.resident).padStart(8)} ${String(u.entities).padStart(8)}`
+ + ` ${String(u.persistent).padStart(10)} ${String(u.inCells).padStart(9)}`
+ + ` ${String(u.unowned).padStart(7)} ${String(u.bodies).padStart(7)}`
+ + ` ${String(u.strayBodies).padStart(5)}`);
+ }
+ console.log(' (entities must be persistent + in cells exactly; a preparation that spawned'
+ + '\n anything would be in the total and in no cell.)');
+
const approach = measured.get('approach');
const teleport = measured.get('teleport');
const sabotage = measured.get('no-prefetch');
@@ -363,12 +407,31 @@ function main() {
[approach.latency50 <= approach.publish * 1.6 + 1,
'a hit costs about what publishing costs, and no preparation',
`${ms(approach.latency50)} ms against ${ms(approach.publish)} ms of publication`],
- [teleport.latency50 >= teleport.prepare + teleport.publish * 0.8,
- 'a miss carries the preparation into the wait',
- `${ms(teleport.latency50)} ms against ${ms(teleport.prepare)} + ${ms(teleport.publish)} ms`],
+ // Not `latency50 >= prepare50 + publish50`: medians of three
+ // distributions have no reason to add up, and that form passed by luck
+ // and then failed by 0.02 ms.
+ [teleport.latency50 >= teleport.publish * 1.6,
+ 'a miss waits for much more than publishing',
+ `${ms(teleport.latency50)} ms against ${ms(teleport.publish)} ms of publication`],
+ [teleport.rows.every((r) => r.latency >= r.publish),
+ 'and every miss contains its own publication',
+ `${teleport.rows.filter((r) => r.latency < r.publish).length} of `
+ + `${teleport.rows.length} arrival(s) shorter than the publication inside them`],
[sabotage.hits === 0,
'and with speculation reaching no further than demand, the same walk hits nothing',
`${sabotage.hits} hit(s), ${sabotage.misses} miss(es)`],
+ // Vacuously true where nothing is prepared, so the arm that has to
+ // answer it is named: a run that readied nothing has not been asked.
+ [approach.unpublished.prepared.length > 0,
+ 'the walk ends with readiness still unclaimed, so there is something to be invisible',
+ `${approach.unpublished.prepared.length} cell(s) prepared and unpublished`],
+ [approach.unpublished.named.length === 0
+ && approach.unpublished.unowned === 0
+ && approach.unpublished.strayBodies === 0
+ && approach.unpublished.stalePhysics === 0,
+ 'and nothing it readied is in the world, the renderer or the solver',
+ `${approach.unpublished.named.length} cell row(s), ${approach.unpublished.unowned} `
+ + `unowned entit(ies), ${approach.unpublished.strayBodies} stray bod(ies)`],
];
console.log('');
let failed = 0;