Defer media loading and strengthen persistence tests
All checks were successful
Deploy Sokko G / deploy (push) Successful in 18s

This commit is contained in:
Shinuwa 2026-09-12 23:28:05 +02:00
parent 09a2d4b71a
commit d0e1fd73b1
19 changed files with 459 additions and 71 deletions

View file

@ -88,26 +88,28 @@ async function instrument(page, expectedCards) {
observer.disconnect();
requestAnimationFrame(() => requestAnimationFrame(() => { metrics.readyMs = performance.now(); }));
}
const getAll = IDBObjectStore.prototype.getAll;
IDBObjectStore.prototype.getAll = function (...args) {
const start = performance.now();
const request = getAll.apply(this, args);
if (this.name === "modules") {
const read = { startMs: start };
metrics.reads.push(read);
request.addEventListener("success", () => {
read.requestMs = performance.now() - start;
read.entries = request.result.length;
});
request.addEventListener("error", () => { read.error = request.error?.message; });
this.transaction.addEventListener("abort", () => { read.error = this.transaction.error?.message; });
this.transaction.addEventListener("complete", () => {
read.transactionMs = performance.now() - start;
checkReady();
});
}
return request;
};
for (const method of ["getAll", "getAllKeys", "get"]) {
const original = IDBObjectStore.prototype[method];
IDBObjectStore.prototype[method] = function (...args) {
const start = performance.now();
const request = original.apply(this, args);
if (this.name === "modules") {
const read = { method, key: args[0], startMs: start };
metrics.reads.push(read);
request.addEventListener("success", () => {
read.requestMs = performance.now() - start;
read.entries = method === "getAllKeys" ? 0 : method === "get" ? Number(request.result != null) : request.result.length;
});
request.addEventListener("error", () => { read.error = request.error?.message; });
this.transaction.addEventListener("abort", () => { read.error = this.transaction.error?.message; });
this.transaction.addEventListener("complete", () => {
read.transactionMs = performance.now() - start;
checkReady();
});
}
return request;
};
}
new PerformanceObserver((list) => {
for (const entry of list.getEntries()) metrics.longTasks.push({ startMs: entry.startTime, durationMs: entry.duration });
}).observe({ type: "longtask", buffered: true });
@ -152,8 +154,8 @@ try {
const sample = await page.evaluate(() => ({ ...window.toolboxProfile, cards: document.querySelectorAll(".toolbox-card").length }));
assert.notEqual(sample.timeOrigin, previousTimeOrigin, "Every sample must load a new document");
previousTimeOrigin = sample.timeOrigin;
assert.equal(sample.reads.length, 1, "Production must perform one initial modules read");
assert.equal(sample.reads[0].entries, dataset.moduleCount);
assert.equal(sample.reads.reduce((sum, read) => sum + read.entries, 0), scenario.toolboxes, "Only memo values should load before opening a toolbox");
assert.ok(sample.reads.every((read) => read.key == null || !String(read.key).endsWith(":images")), "Closed image modules must stay on disk");
assert.equal(sample.cards, scenario.toolboxes);
assert.deepEqual(errors, []);
await cdp.send("HeapProfiler.collectGarbage");
@ -166,7 +168,7 @@ try {
const summary = {
readyMedianMs: median(samples.map((sample) => sample.readyMs)),
readyMaxMs: Math.max(...samples.map((sample) => sample.readyMs)),
readMedianMs: median(samples.map((sample) => sample.reads[0].transactionMs)),
readMedianMs: median(samples.map((sample) => Math.max(...sample.reads.map((read) => read.startMs + read.transactionMs)) - Math.min(...sample.reads.map((read) => read.startMs)))),
heapMedianMiB: median(samples.map((sample) => sample.jsHeapBytes / 1024 ** 2)),
longestTaskMs: Math.max(0, ...samples.flatMap((sample) => sample.longTasks.map((task) => task.durationMs)))
};