roamwright 0.61.20 → 0.61.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -12
- package/examples/scenes.html +54 -0
- package/examples/scenes.js +594 -0
- package/geometry/projectile-shapes.js +85 -0
- package/index.js +50 -0
- package/motion/fallen-mount.js +63 -0
- package/motion/melee-combat.js +328 -0
- package/motion/melee-cuts.js +395 -0
- package/motion/melee-duels.js +142 -0
- package/motion/melee-exchange-creatures.js +86 -0
- package/motion/melee-exchange.js +498 -0
- package/motion/melee-reactions.js +147 -0
- package/motion/prop-contact.js +87 -0
- package/package.json +1 -1
- package/rendering/blade-trails.js +128 -0
- package/rendering/scene-beams.js +486 -0
- package/rendering/scene-coverage.js +500 -0
- package/rendering/scene-markers.js +421 -0
- package/rendering/scene-projectiles.js +395 -0
- package/rendering/scene-props.js +383 -0
- package/rendering/scene-shots.js +199 -0
- package/runtime/foley-surface.js +79 -0
- package/runtime/scene-script.js +137 -0
- package/runtime/scene-zones.js +117 -0
- package/tools/README.md +34 -25
- package/tools/cpu-profile.cjs +117 -0
- package/tools/cpu-profile.test.cjs +31 -1
- package/tools/figure-inspect.cjs +475 -0
- package/tools/figure-inspect.test.cjs +153 -0
- package/tools/geometry-hash.cjs +361 -0
- package/tools/geometry-hash.test.cjs +146 -0
- package/tools/load-audit.cjs +199 -2
- package/tools/load-audit.test.cjs +68 -0
- package/tools/quiet-bench.cjs +202 -0
- package/tools/quiet-bench.test.cjs +91 -0
- package/tools/scene-detail.cjs +355 -0
- package/tools/scene-detail.test.cjs +162 -0
- package/tools/scrub-clear.cjs +191 -0
- package/tools/scrub-clear.test.cjs +100 -0
- package/tools/tree-inspect.cjs +271 -0
- package/tools/tree-inspect.test.cjs +123 -0
- package/tools/world-tour.cjs +223 -0
- package/tools/world-tour.test.cjs +77 -0
package/tools/load-audit.cjs
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
// Load timing (`runReady`), stalled-load diagnostics (`runLoadDiag`),
|
|
1
|
+
// Load timing (`runReady`), stalled-load diagnostics (`runLoadDiag`), invalid WebGL program watch (`runGlWatch`),
|
|
2
|
+
// ground-shaping first-visit timing (`runShapeTiming`), and cold throttled scene-set fetch timing (`runColdSetFetch`).
|
|
2
3
|
'use strict';
|
|
3
4
|
const { renewShaders, renewalFlags, saltFor } = require('./shader-renewal.cjs');
|
|
5
|
+
const { startSceneInPage } = require('./scene-run.cjs');
|
|
6
|
+
|
|
7
|
+
/** Chrome DevTools / Lighthouse network throttle presets (latency in ms, throughput in bytes/s). */
|
|
8
|
+
const NETWORK_PROFILES = {
|
|
9
|
+
slow4g: { latency: 562.5, downloadThroughput: (1.6 * 1024 * 1024 * 0.9) / 8, uploadThroughput: (750 * 1024 * 0.9) / 8 },
|
|
10
|
+
fast4g: { latency: 165, downloadThroughput: (9 * 1024 * 1024 * 0.9) / 8, uploadThroughput: (1.5 * 1024 * 1024 * 0.9) / 8 },
|
|
11
|
+
none: null,
|
|
12
|
+
};
|
|
4
13
|
|
|
5
14
|
/**
|
|
6
15
|
* Measures step-by-step time to ready and post-entry long frames across rounds, addresses, and optional comparison
|
|
@@ -198,4 +207,192 @@ async function runGlWatch(driver, { address = '', waitMs = 8000 } = {}) {
|
|
|
198
207
|
return bad;
|
|
199
208
|
}
|
|
200
209
|
|
|
201
|
-
|
|
210
|
+
/**
|
|
211
|
+
* Parses CLI arguments for `runShapeTiming`: `<rounds> <address...>`.
|
|
212
|
+
*
|
|
213
|
+
* @param {string[]} [argv=[]]
|
|
214
|
+
* @returns {{ rounds: number, paths: string[] }}
|
|
215
|
+
*/
|
|
216
|
+
function parseShapeArgs(argv = []) {
|
|
217
|
+
const [rounds = '1', ...paths] = argv;
|
|
218
|
+
return { rounds: +rounds || 1, paths: paths.length ? paths : [''] };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Reads the terrain-shaping step duration and total ready time from `window[debug].loadTimes`.
|
|
223
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
224
|
+
*
|
|
225
|
+
* @param {{ debug: string, stepPattern?: string }} arg
|
|
226
|
+
* @returns {{ shape: number|undefined, ready: number }}
|
|
227
|
+
*/
|
|
228
|
+
function readShapeTimeInPage({ debug, stepPattern = '^Shaping' }) {
|
|
229
|
+
const lt = window[debug].loadTimes;
|
|
230
|
+
const re = new RegExp(stepPattern);
|
|
231
|
+
return {
|
|
232
|
+
shape: lt.find(([name]) => re.test(name))?.[1],
|
|
233
|
+
ready: Math.round(lt.ready),
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Formats the summary line for one address in `runShapeTiming`.
|
|
239
|
+
*
|
|
240
|
+
* @param {string} routePath Route address.
|
|
241
|
+
* @param {{ shape: number[], ready: number[] }} record Measured shaping and ready times in ms.
|
|
242
|
+
* @returns {string}
|
|
243
|
+
*/
|
|
244
|
+
function formatShapeSummary(routePath, record) {
|
|
245
|
+
return `${routePath} shaping: least ${Math.min(...record.shape)} of ${record.shape.join(' ')} | ready: least ${Math.min(...record.ready)} of ${record.ready.join(' ')}`;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Measures the ground-shaping step and total time-to-ready on fresh browser contexts across rounds and addresses.
|
|
250
|
+
*
|
|
251
|
+
* @param {object} driver Page driver from `createPageDriver`.
|
|
252
|
+
* @param {object} [options]
|
|
253
|
+
* @param {string[]} [options.argv=[]] Raw CLI arguments (`<rounds> <address...>`).
|
|
254
|
+
* @param {string} [options.stepPattern='^Shaping'] Regex source matching the shaping step name in `loadTimes`.
|
|
255
|
+
* @returns {Promise<Record<string, { shape: number[], ready: number[] }>>}
|
|
256
|
+
*/
|
|
257
|
+
async function runShapeTiming(driver, { argv = [], stepPattern = '^Shaping' } = {}) {
|
|
258
|
+
const { rounds, paths } = parseShapeArgs(argv);
|
|
259
|
+
const debug = driver.debug;
|
|
260
|
+
const browser = await driver.chromium.launch({ executablePath: driver.shell, ...driver.GPU });
|
|
261
|
+
const out = {};
|
|
262
|
+
for (let r = 0; r < rounds; r++) {
|
|
263
|
+
for (const routePath of paths) {
|
|
264
|
+
const ctx = await browser.newContext({ viewport: { width: 1280, height: 720 } });
|
|
265
|
+
await driver.applyStorage(ctx, { quality: 'high', muted: '1' });
|
|
266
|
+
const page = await ctx.newPage();
|
|
267
|
+
page.on('pageerror', e => console.log('PAGE ERROR', e.message.slice(0, 200)));
|
|
268
|
+
await driver.enter(page, driver.routeUrl(routePath));
|
|
269
|
+
await page.waitForTimeout(1500);
|
|
270
|
+
const t = await page.evaluate(readShapeTimeInPage, { debug, stepPattern });
|
|
271
|
+
(out[routePath] ??= { shape: [], ready: [] }).shape.push(t.shape);
|
|
272
|
+
out[routePath].ready.push(t.ready);
|
|
273
|
+
await ctx.close();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
for (const [routePath, record] of Object.entries(out)) console.log(formatShapeSummary(routePath, record));
|
|
277
|
+
await driver.closeBrowser(browser);
|
|
278
|
+
return out;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Parses CLI arguments for `runColdSetFetch`: `<address> <profile: fast4g | slow4g | none> <set id>...`.
|
|
283
|
+
*
|
|
284
|
+
* @param {string[]} [argv=[]]
|
|
285
|
+
* @returns {{ address: string, profile: string, sets: string[] }}
|
|
286
|
+
*/
|
|
287
|
+
function parseColdSetArgs(argv = []) {
|
|
288
|
+
const [address = '', profile = 'none', ...sets] = argv;
|
|
289
|
+
return { address, profile, sets };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Looks up the first catalog event id that uses a given lazy set id.
|
|
294
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
295
|
+
*
|
|
296
|
+
* @param {{ debug: string, setId: string }} arg
|
|
297
|
+
* @returns {string|undefined}
|
|
298
|
+
*/
|
|
299
|
+
function findEventBySetInPage({ debug, setId }) {
|
|
300
|
+
return window[debug].CONFIG.events.find(e => e.set === setId)?.id;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Checks whether the scene director has begun the requested event id.
|
|
305
|
+
* Passed to `page.waitForFunction`; must remain self-contained.
|
|
306
|
+
*
|
|
307
|
+
* @param {{ debug: string, id: string }} arg
|
|
308
|
+
* @returns {boolean}
|
|
309
|
+
*/
|
|
310
|
+
function waitSceneActiveInPage({ debug, id }) {
|
|
311
|
+
return window[debug].director.ev?.id === id;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Formats the summary headline and per-script rows for one cold scene-set fetch measurement.
|
|
316
|
+
*
|
|
317
|
+
* @param {string} setId Lazy set identifier.
|
|
318
|
+
* @param {string|undefined} eventId Scene event identifier.
|
|
319
|
+
* @param {string} profile Throttle profile name.
|
|
320
|
+
* @param {boolean} began Whether the scene began within the timeout.
|
|
321
|
+
* @param {number} seconds Elapsed wall-clock seconds from start to scene begin.
|
|
322
|
+
* @param {Array<{ url: string, start: number, end?: number, bytes?: number }>} requests Recorded network requests.
|
|
323
|
+
* @returns {{ headline: string, rows: string[], bytes: number }}
|
|
324
|
+
*/
|
|
325
|
+
function formatColdSetReport(setId, eventId, profile, began, seconds, requests) {
|
|
326
|
+
const first = requests.length ? Math.min(...requests.map(r => r.start)) : 0;
|
|
327
|
+
const scripts = requests.filter(r => /\.js$/.test(r.url));
|
|
328
|
+
const rows = scripts.map(r => `${r.url} ${r.bytes ?? '?'} B, done at ${r.end ? (r.end - first).toFixed(2) : '?'} s`);
|
|
329
|
+
const bytes = scripts.reduce((s, r) => s + (r.bytes || 0), 0);
|
|
330
|
+
const headline = `${setId} (scene ${eventId}, ${profile}): ${began ? 'began' : 'did NOT begin'} ${seconds.toFixed(2)} s after the start; scripts ${bytes} B on the wire`;
|
|
331
|
+
return { headline, rows, bytes };
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Measures cold scene-set fetch latency and wire bytes over an emulated network profile after entering the world.
|
|
336
|
+
*
|
|
337
|
+
* @param {object} driver Page driver from `createPageDriver`.
|
|
338
|
+
* @param {object} [options]
|
|
339
|
+
* @param {string[]} [options.argv=[]] Raw CLI arguments (`<address> <profile> <setId...>`).
|
|
340
|
+
* @param {string} [options.publishedHost=''] Optional published hostname where routes use `<BASE><address>/` instead of `?r=`.
|
|
341
|
+
* @param {Record<string, object|null>} [options.profiles=NETWORK_PROFILES] Network throttle profiles.
|
|
342
|
+
* @returns {Promise<Array<{ set: string, eventId: string|undefined, began: boolean, seconds: number, bytes: number }>>}
|
|
343
|
+
*/
|
|
344
|
+
async function runColdSetFetch(driver, { argv = [], publishedHost = '', profiles = NETWORK_PROFILES } = {}) {
|
|
345
|
+
const { address, profile, sets } = parseColdSetArgs(argv);
|
|
346
|
+
const debug = driver.debug;
|
|
347
|
+
const url = publishedHost && driver.BASE.includes(publishedHost) ? driver.BASE + address + '/' : driver.BASE + '?r=' + address;
|
|
348
|
+
const browser = await driver.chromium.launch({ executablePath: driver.shell, ...driver.GPU });
|
|
349
|
+
const results = [];
|
|
350
|
+
for (const setId of sets) {
|
|
351
|
+
const ctx = await browser.newContext({ viewport: { width: 960, height: 540 }, serviceWorkers: 'block' });
|
|
352
|
+
const page = await ctx.newPage();
|
|
353
|
+
await driver.applyStorage(page, { quality: 'medium' });
|
|
354
|
+
page.on('pageerror', e => console.log('PAGE ERROR', e.message.slice(0, 200)));
|
|
355
|
+
await driver.enter(page, url);
|
|
356
|
+
await page.waitForTimeout(4000);
|
|
357
|
+
const cdp = await ctx.newCDPSession(page);
|
|
358
|
+
await cdp.send('Network.enable');
|
|
359
|
+
if (profiles[profile]) await cdp.send('Network.emulateNetworkConditions', { offline: false, ...profiles[profile] });
|
|
360
|
+
const requests = new Map();
|
|
361
|
+
cdp.on('Network.requestWillBeSent', e => requests.set(e.requestId, { url: e.request.url.split('/').pop(), start: e.timestamp }));
|
|
362
|
+
cdp.on('Network.loadingFinished', e => {
|
|
363
|
+
const r = requests.get(e.requestId);
|
|
364
|
+
if (r) Object.assign(r, { end: e.timestamp, bytes: e.encodedDataLength });
|
|
365
|
+
});
|
|
366
|
+
const ev = await page.evaluate(findEventBySetInPage, { debug, setId });
|
|
367
|
+
const wall0 = Date.now();
|
|
368
|
+
await page.evaluate(startSceneInPage, { debug, id: ev });
|
|
369
|
+
const began = await page.waitForFunction(waitSceneActiveInPage, { debug, id: ev }, { timeout: 120000, polling: 50 }).then(
|
|
370
|
+
() => true,
|
|
371
|
+
() => false,
|
|
372
|
+
);
|
|
373
|
+
const seconds = (Date.now() - wall0) / 1000;
|
|
374
|
+
const report = formatColdSetReport(setId, ev, profile, began, seconds, [...requests.values()]);
|
|
375
|
+
console.log(report.headline);
|
|
376
|
+
for (const row of report.rows) console.log(' ', row);
|
|
377
|
+
results.push({ set: setId, eventId: ev, began, seconds, bytes: report.bytes });
|
|
378
|
+
await ctx.close();
|
|
379
|
+
}
|
|
380
|
+
await browser.close();
|
|
381
|
+
return results;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
module.exports = {
|
|
385
|
+
NETWORK_PROFILES,
|
|
386
|
+
findEventBySetInPage,
|
|
387
|
+
formatColdSetReport,
|
|
388
|
+
formatShapeSummary,
|
|
389
|
+
parseColdSetArgs,
|
|
390
|
+
parseShapeArgs,
|
|
391
|
+
readShapeTimeInPage,
|
|
392
|
+
runColdSetFetch,
|
|
393
|
+
runGlWatch,
|
|
394
|
+
runLoadDiag,
|
|
395
|
+
runReady,
|
|
396
|
+
runShapeTiming,
|
|
397
|
+
waitSceneActiveInPage,
|
|
398
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const test = require('node:test');
|
|
4
|
+
const {
|
|
5
|
+
NETWORK_PROFILES,
|
|
6
|
+
findEventBySetInPage,
|
|
7
|
+
formatColdSetReport,
|
|
8
|
+
formatShapeSummary,
|
|
9
|
+
parseColdSetArgs,
|
|
10
|
+
parseShapeArgs,
|
|
11
|
+
readShapeTimeInPage,
|
|
12
|
+
waitSceneActiveInPage,
|
|
13
|
+
} = require('./load-audit.cjs');
|
|
14
|
+
|
|
15
|
+
test('parseShapeArgs and formatShapeSummary handle rounds, routes, and min summaries', () => {
|
|
16
|
+
assert.deepEqual(parseShapeArgs(['3', 'location/valley', 'location/coast']), {
|
|
17
|
+
rounds: 3,
|
|
18
|
+
paths: ['location/valley', 'location/coast'],
|
|
19
|
+
});
|
|
20
|
+
assert.deepEqual(parseShapeArgs([]), { rounds: 1, paths: [''] });
|
|
21
|
+
assert.equal(
|
|
22
|
+
formatShapeSummary('location/valley', { shape: [425, 410], ready: [850, 830] }),
|
|
23
|
+
'location/valley shaping: least 410 of 425 410 | ready: least 830 of 850 830',
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('parseColdSetArgs, NETWORK_PROFILES, and formatColdSetReport format wire totals accurately', () => {
|
|
28
|
+
assert.deepEqual(parseColdSetArgs(['location/harbour', 'fast4g', 'market', 'oasis']), {
|
|
29
|
+
address: 'location/harbour',
|
|
30
|
+
profile: 'fast4g',
|
|
31
|
+
sets: ['market', 'oasis'],
|
|
32
|
+
});
|
|
33
|
+
assert.equal(NETWORK_PROFILES.none, null);
|
|
34
|
+
assert.equal(NETWORK_PROFILES.fast4g.latency, 165);
|
|
35
|
+
assert.equal(NETWORK_PROFILES.slow4g.latency, 562.5);
|
|
36
|
+
|
|
37
|
+
const report = formatColdSetReport('market', 'market_scene', 'fast4g', true, 1.45, [
|
|
38
|
+
{ url: 'set-a.js', start: 10, end: 10.6, bytes: 30000 },
|
|
39
|
+
{ url: 'style.css', start: 10.1, end: 10.2, bytes: 500 },
|
|
40
|
+
{ url: 'set-b.js', start: 10.2, end: 11.1, bytes: 18200 },
|
|
41
|
+
]);
|
|
42
|
+
assert.equal(report.bytes, 48200);
|
|
43
|
+
assert.equal(report.headline, 'market (scene market_scene, fast4g): began 1.45 s after the start; scripts 48200 B on the wire');
|
|
44
|
+
assert.deepEqual(report.rows, ['set-a.js 30000 B, done at 0.60 s', 'set-b.js 18200 B, done at 1.10 s']);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('load-audit in-page helpers talk strictly through window[debug]', () => {
|
|
48
|
+
const lt = [
|
|
49
|
+
['Boot', 110],
|
|
50
|
+
['Shaping terrain', 395],
|
|
51
|
+
];
|
|
52
|
+
lt.ready = 805.4;
|
|
53
|
+
globalThis.window = {
|
|
54
|
+
APP: {
|
|
55
|
+
loadTimes: lt,
|
|
56
|
+
CONFIG: { events: [{ id: 'market_scene', set: 'market' }] },
|
|
57
|
+
director: { ev: { id: 'market_scene' } },
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
try {
|
|
61
|
+
assert.deepEqual(readShapeTimeInPage({ debug: 'APP' }), { shape: 395, ready: 805 });
|
|
62
|
+
assert.equal(findEventBySetInPage({ debug: 'APP', setId: 'market' }), 'market_scene');
|
|
63
|
+
assert.equal(waitSceneActiveInPage({ debug: 'APP', id: 'market_scene' }), true);
|
|
64
|
+
assert.equal(waitSceneActiveInPage({ debug: 'APP', id: 'other' }), false);
|
|
65
|
+
} finally {
|
|
66
|
+
delete globalThis.window;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// Quiet-machine benchmark runner: measures first and repeat load times across lands, post-GC memory usage,
|
|
2
|
+
// GPU renderer identity, fixed-view perfTest rows, and opening-view stageTimes breakdowns.
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parses CLI arguments for `runQuietBench`.
|
|
7
|
+
*
|
|
8
|
+
* @param {string[]} [argv=[]] Raw CLI arguments (`[subpath]`).
|
|
9
|
+
* @returns {{ subpath: string }}
|
|
10
|
+
*/
|
|
11
|
+
function parseQuietBenchArgs(argv = []) {
|
|
12
|
+
return { subpath: argv[0] || '' };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Formats a single load-timing summary line.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} label Display label for the route.
|
|
19
|
+
* @param {string} visit `'first'` or `'later'`.
|
|
20
|
+
* @param {{ steps: Array<[string, number]>, ready: number }} loadTimes
|
|
21
|
+
* @returns {string}
|
|
22
|
+
*/
|
|
23
|
+
function formatLoadLine(label, visit, loadTimes) {
|
|
24
|
+
const steps = loadTimes.steps || [];
|
|
25
|
+
const afterBoot = steps.slice(1).reduce((a, b) => a + b[1], 0);
|
|
26
|
+
const bootMs = steps[0] ? steps[0][1] : 0;
|
|
27
|
+
return `load ${label} ${visit}: ready ${Math.round(loadTimes.ready)} ms, ${afterBoot} ms of steps after ${bootMs} ms; ${JSON.stringify(steps.map(x => x[1]))}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Formats a post-GC memory usage summary line.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} label Display label for the route.
|
|
34
|
+
* @param {{ usedSize: number, embedderHeapUsedSize?: number, backingStorageSize?: number }} heap CDP heap usage.
|
|
35
|
+
* @param {number|null} perfMem `performance.memory.usedJSHeapSize` in bytes.
|
|
36
|
+
* @returns {string}
|
|
37
|
+
*/
|
|
38
|
+
function formatMemoryLine(label, heap, perfMem) {
|
|
39
|
+
return `memory ${label}: heap ${(heap.usedSize / 1e6).toFixed(0)} MB (objects), embedder ${((heap.embedderHeapUsedSize || 0) / 1e6).toFixed(0)} MB, backing ${((heap.backingStorageSize || 0) / 1e6).toFixed(0)} MB, performance.memory ${((perfMem || 0) / 1e6).toFixed(0)} MB`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Formats a single fixed-view benchmark row from `perfTest()`.
|
|
44
|
+
*
|
|
45
|
+
* @param {{ ms: number, cpu: number, calls: number, tris: number, view: string }} row
|
|
46
|
+
* @returns {string}
|
|
47
|
+
*/
|
|
48
|
+
function formatPerfRow(row) {
|
|
49
|
+
return `${String(row.ms).padStart(6)} ms cpu ${String(row.cpu).padStart(5)} calls ${String(row.calls).padStart(4)} tris ${String(row.tris).padStart(8)} ${row.view}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Reads `loadTimes` steps and `.ready` total from `window[debug]`.
|
|
54
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
55
|
+
*
|
|
56
|
+
* @param {{ debug: string }} arg
|
|
57
|
+
* @returns {{ steps: Array<[string, number]>, ready: number }}
|
|
58
|
+
*/
|
|
59
|
+
function readLoadTimesInPage({ debug }) {
|
|
60
|
+
const lt = window[debug].loadTimes;
|
|
61
|
+
return { steps: [...lt], ready: lt.ready };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Reads `performance.memory.usedJSHeapSize` when available.
|
|
66
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
67
|
+
*
|
|
68
|
+
* @returns {number|undefined}
|
|
69
|
+
*/
|
|
70
|
+
function readPerfMemoryInPage() {
|
|
71
|
+
return performance.memory && performance.memory.usedJSHeapSize;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Reads the unmasked WebGL renderer string from `window[debug].renderer`.
|
|
76
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
77
|
+
*
|
|
78
|
+
* @param {{ debug: string }} arg
|
|
79
|
+
* @returns {string|null}
|
|
80
|
+
*/
|
|
81
|
+
function readGpuRendererInPage({ debug }) {
|
|
82
|
+
const gl = window[debug].renderer.getContext();
|
|
83
|
+
const ext = gl.getExtension('WEBGL_debug_renderer_info');
|
|
84
|
+
return ext ? gl.getParameter(ext.UNMASKED_RENDERER_WEBGL) : null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Runs the world's `perfTest()` suite inside the page and returns serializable rows.
|
|
89
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
90
|
+
*
|
|
91
|
+
* @param {{ debug: string }} arg
|
|
92
|
+
* @returns {Promise<{ size: string, quality: string, rows: Array<object> }>}
|
|
93
|
+
*/
|
|
94
|
+
async function runPerfTestInPage({ debug }) {
|
|
95
|
+
const app = window[debug];
|
|
96
|
+
const r = await app.perfTest();
|
|
97
|
+
return { size: r.size, quality: app.state.quality, rows: r.map(x => ({ ...x })) };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Freezes the opening view at `hour`, warms the GPU pipeline, and measures `stageTimes()`.
|
|
102
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
103
|
+
*
|
|
104
|
+
* @param {{ debug: string, hour: number, warmupRounds: number }} arg
|
|
105
|
+
* @returns {Promise<object>}
|
|
106
|
+
*/
|
|
107
|
+
async function measureOpeningPartsInPage({ debug, hour, warmupRounds }) {
|
|
108
|
+
const app = window[debug];
|
|
109
|
+
app.holdQuality(true);
|
|
110
|
+
app.env.flow = false;
|
|
111
|
+
app.env.time = hour;
|
|
112
|
+
app.state.mode = 'inspect';
|
|
113
|
+
for (let i = 0; i < warmupRounds; i++) {
|
|
114
|
+
await app.bench(3);
|
|
115
|
+
await new Promise(r => setTimeout(r, 80));
|
|
116
|
+
}
|
|
117
|
+
return app.stageTimes();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Runs the full quiet-machine benchmark: first/repeat loads, post-GC heap/backing memory,
|
|
122
|
+
* GPU renderer string, fixed-view `perfTest()`, and opening-view `stageTimes()`.
|
|
123
|
+
*
|
|
124
|
+
* @param {object} driver Page driver from `createPageDriver`.
|
|
125
|
+
* @param {object} [options]
|
|
126
|
+
* @param {string[]} [options.argv=[]] Raw CLI arguments (`[subpath]`).
|
|
127
|
+
* @param {Array<{ path: string, label?: string }>} [options.routes] Routes to measure first and repeat loads on.
|
|
128
|
+
* @param {number} [options.openingHour=0.715] Time of day (`0..1`) for opening-view `stageTimes()`.
|
|
129
|
+
* @param {number} [options.warmupRounds=25] Warm-up `bench(3)` rounds before `stageTimes()`.
|
|
130
|
+
* @param {{ width: number, height: number }} [options.viewport]
|
|
131
|
+
* @param {number} [options.dsf=2]
|
|
132
|
+
* @returns {Promise<{ gpu: string|null, perfTest: object, openingParts: object }>}
|
|
133
|
+
*/
|
|
134
|
+
async function runQuietBench(
|
|
135
|
+
driver,
|
|
136
|
+
{
|
|
137
|
+
argv = [],
|
|
138
|
+
routes = [{ path: '', label: 'default' }],
|
|
139
|
+
openingHour = 0.715,
|
|
140
|
+
warmupRounds = 25,
|
|
141
|
+
viewport = { width: 1728, height: 1117 },
|
|
142
|
+
dsf = 2,
|
|
143
|
+
} = {},
|
|
144
|
+
) {
|
|
145
|
+
const { subpath } = parseQuietBenchArgs(argv);
|
|
146
|
+
const base = driver.BASE + subpath;
|
|
147
|
+
const debug = driver.debug;
|
|
148
|
+
const browser = await driver.chromium.launch({ executablePath: driver.shell, ...driver.GPU });
|
|
149
|
+
const ctx = await browser.newContext({ viewport, deviceScaleFactor: dsf });
|
|
150
|
+
await driver.applyStorage(ctx, { quality: 'high', 'quality-fit': 'high', muted: '1' });
|
|
151
|
+
|
|
152
|
+
const open = async routePath => {
|
|
153
|
+
const page = await ctx.newPage();
|
|
154
|
+
page.on('pageerror', e => console.log('PAGE ERROR', e.message.slice(0, 200)));
|
|
155
|
+
await driver.enter(page, base + routePath, { waitUntil: 'load', titledMs: 180000 });
|
|
156
|
+
return page;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
for (const route of routes) {
|
|
160
|
+
const routePath = typeof route === 'string' ? route : route.path;
|
|
161
|
+
const label = typeof route === 'string' ? route || 'default' : route.label || route.path || 'default';
|
|
162
|
+
for (const visit of ['first', 'later']) {
|
|
163
|
+
const page = await open(routePath);
|
|
164
|
+
await page.waitForTimeout(1500);
|
|
165
|
+
const lt = await page.evaluate(readLoadTimesInPage, { debug });
|
|
166
|
+
console.log(formatLoadLine(label, visit, lt));
|
|
167
|
+
if (visit === 'later') {
|
|
168
|
+
const cdp = await ctx.newCDPSession(page);
|
|
169
|
+
await cdp.send('HeapProfiler.collectGarbage');
|
|
170
|
+
const heap = await cdp.send('Runtime.getHeapUsage');
|
|
171
|
+
const mem = await page.evaluate(readPerfMemoryInPage);
|
|
172
|
+
console.log(formatMemoryLine(label, heap, mem));
|
|
173
|
+
}
|
|
174
|
+
await page.close();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const page = await open('');
|
|
179
|
+
const gpu = await page.evaluate(readGpuRendererInPage, { debug });
|
|
180
|
+
console.log('gpu', gpu);
|
|
181
|
+
await page.waitForTimeout(2500);
|
|
182
|
+
const perfTest = await page.evaluate(runPerfTestInPage, { debug });
|
|
183
|
+
console.log('perfTest', perfTest.size, 'quality', perfTest.quality);
|
|
184
|
+
for (const row of perfTest.rows) console.log(formatPerfRow(row));
|
|
185
|
+
const openingParts = await page.evaluate(measureOpeningPartsInPage, { debug, hour: openingHour, warmupRounds });
|
|
186
|
+
console.log('opening view parts', JSON.stringify(openingParts));
|
|
187
|
+
await browser.close();
|
|
188
|
+
return { gpu, perfTest, openingParts };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
module.exports = {
|
|
192
|
+
formatLoadLine,
|
|
193
|
+
formatMemoryLine,
|
|
194
|
+
formatPerfRow,
|
|
195
|
+
measureOpeningPartsInPage,
|
|
196
|
+
parseQuietBenchArgs,
|
|
197
|
+
readGpuRendererInPage,
|
|
198
|
+
readLoadTimesInPage,
|
|
199
|
+
readPerfMemoryInPage,
|
|
200
|
+
runPerfTestInPage,
|
|
201
|
+
runQuietBench,
|
|
202
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const test = require('node:test');
|
|
4
|
+
const {
|
|
5
|
+
formatLoadLine,
|
|
6
|
+
formatMemoryLine,
|
|
7
|
+
formatPerfRow,
|
|
8
|
+
measureOpeningPartsInPage,
|
|
9
|
+
parseQuietBenchArgs,
|
|
10
|
+
readGpuRendererInPage,
|
|
11
|
+
readLoadTimesInPage,
|
|
12
|
+
runPerfTestInPage,
|
|
13
|
+
} = require('./quiet-bench.cjs');
|
|
14
|
+
|
|
15
|
+
test('parseQuietBenchArgs and quiet-bench formatters produce stable output lines', () => {
|
|
16
|
+
assert.deepEqual(parseQuietBenchArgs(['site/']), { subpath: 'site/' });
|
|
17
|
+
assert.deepEqual(parseQuietBenchArgs([]), { subpath: '' });
|
|
18
|
+
|
|
19
|
+
const loadLine = formatLoadLine('valley', 'first', {
|
|
20
|
+
steps: [
|
|
21
|
+
['Boot', 120],
|
|
22
|
+
['Shaping terrain', 410],
|
|
23
|
+
['Preparing shaders', 300],
|
|
24
|
+
],
|
|
25
|
+
ready: 830,
|
|
26
|
+
});
|
|
27
|
+
assert.equal(loadLine, 'load valley first: ready 830 ms, 710 ms of steps after 120 ms; [120,410,300]');
|
|
28
|
+
|
|
29
|
+
const memLine = formatMemoryLine('valley', { usedSize: 35e6, embedderHeapUsedSize: 12e6, backingStorageSize: 80e6 }, 44e6);
|
|
30
|
+
assert.equal(memLine, 'memory valley: heap 35 MB (objects), embedder 12 MB, backing 80 MB, performance.memory 44 MB');
|
|
31
|
+
|
|
32
|
+
assert.equal(
|
|
33
|
+
formatPerfRow({ ms: 9.4, cpu: 3.2, calls: 142, tris: 410000, view: 'harbour' }),
|
|
34
|
+
' 9.4 ms cpu 3.2 calls 142 tris 410000 harbour',
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('quiet-bench in-page helpers talk strictly through window[debug]', async () => {
|
|
39
|
+
let held = false;
|
|
40
|
+
let benched = 0;
|
|
41
|
+
const lt = [
|
|
42
|
+
['Boot', 50],
|
|
43
|
+
['Ground', 150],
|
|
44
|
+
];
|
|
45
|
+
lt.ready = 200;
|
|
46
|
+
const perfRows = [{ ms: 8.1, cpu: 2.1, calls: 90, tris: 100000, view: 'opening' }];
|
|
47
|
+
perfRows.size = '3456x2234';
|
|
48
|
+
globalThis.window = {
|
|
49
|
+
APP: {
|
|
50
|
+
loadTimes: lt,
|
|
51
|
+
state: { quality: 'high', mode: 'play' },
|
|
52
|
+
env: { flow: true, time: 0.5 },
|
|
53
|
+
renderer: {
|
|
54
|
+
getContext: () => ({
|
|
55
|
+
getExtension: () => ({ UNMASKED_RENDERER_WEBGL: 0x9246 }),
|
|
56
|
+
getParameter: p => (p === 0x9246 ? 'Mock GPU' : null),
|
|
57
|
+
}),
|
|
58
|
+
},
|
|
59
|
+
holdQuality(flag) {
|
|
60
|
+
held = flag;
|
|
61
|
+
},
|
|
62
|
+
async bench() {
|
|
63
|
+
benched++;
|
|
64
|
+
},
|
|
65
|
+
async perfTest() {
|
|
66
|
+
return perfRows;
|
|
67
|
+
},
|
|
68
|
+
async stageTimes() {
|
|
69
|
+
return { whole: 8.1, shadows: 1.2 };
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
try {
|
|
74
|
+
assert.deepEqual(readLoadTimesInPage({ debug: 'APP' }), { steps: [...lt], ready: 200 });
|
|
75
|
+
assert.equal(readGpuRendererInPage({ debug: 'APP' }), 'Mock GPU');
|
|
76
|
+
assert.deepEqual(await runPerfTestInPage({ debug: 'APP' }), {
|
|
77
|
+
size: '3456x2234',
|
|
78
|
+
quality: 'high',
|
|
79
|
+
rows: [{ ms: 8.1, cpu: 2.1, calls: 90, tris: 100000, view: 'opening' }],
|
|
80
|
+
});
|
|
81
|
+
const parts = await measureOpeningPartsInPage({ debug: 'APP', hour: 0.715, warmupRounds: 1 });
|
|
82
|
+
assert.equal(held, true);
|
|
83
|
+
assert.equal(benched, 1);
|
|
84
|
+
assert.equal(globalThis.window.APP.env.flow, false);
|
|
85
|
+
assert.equal(globalThis.window.APP.env.time, 0.715);
|
|
86
|
+
assert.equal(globalThis.window.APP.state.mode, 'inspect');
|
|
87
|
+
assert.deepEqual(parts, { whole: 8.1, shadows: 1.2 });
|
|
88
|
+
} finally {
|
|
89
|
+
delete globalThis.window;
|
|
90
|
+
}
|
|
91
|
+
});
|