The container-only harness was measuring the wrong thing. Real usage — several tabs, several boards, clicking into widgets — reaches ~880 MB server and a 650 MB *browser* heap, and the browser was never measured at all. Profiling build: `docker build --build-arg HOMARR_PROFILING=true . -t homarr:performance`. React's production bundle strips the hooks DevTools needs, hence "Profiling not supported". Note reactProductionProfiling in next.config is read only by the webpack path; under Turbopack it comes from `next build --profile`, and turbo strips any env var not declared in the task's `env`, so all three had to line up before the flag actually took effect — verified by markers present only in React's profiling bundle, and static chunks going 20 -> 84 MB with source maps. inspect-container.mts attaches to an already-running container (SIGUSR1 opens Node's inspector — no rebuild, no restart), reports cgroup/per-process/V8 memory and can pull a heap snapshot out over CDP. The inspected context has no require and no dynamic import, so it reads globals and uses CDP domains instead. analyze-heapsnapshot / analyze-react-fibers / analyze-heap-retainers summarise a snapshot too large for DevTools to open. Harness now opens STRESS_BOARDS across STRESS_TABS_PER_BOARD tabs, clicks into widgets, and records browser heap, DOM nodes and listener count via CDP. Performance.getMetrics silently returns nothing unless the domain is enabled, which is why the first run reported a 0 MiB client heap.
65 lines
2.5 KiB
JavaScript
65 lines
2.5 KiB
JavaScript
// Aggregates a Chrome .heapsnapshot by shallow (self) size per constructor/type,
|
|
// which is what "Summary" view in DevTools shows. Retained size needs graph
|
|
// traversal; shallow is usually enough to identify a dominant allocator.
|
|
import { readFileSync } from "node:fs";
|
|
|
|
const file = process.argv[2];
|
|
const raw = readFileSync(file, "utf8");
|
|
const snap = JSON.parse(raw);
|
|
|
|
const meta = snap.snapshot.meta;
|
|
const nodeFields = meta.node_fields;
|
|
const nodeTypes = meta.node_types[0];
|
|
const stride = nodeFields.length;
|
|
const iType = nodeFields.indexOf("type");
|
|
const iName = nodeFields.indexOf("name");
|
|
const iSelf = nodeFields.indexOf("self_size");
|
|
|
|
const nodes = snap.nodes;
|
|
const strings = snap.strings;
|
|
const count = snap.snapshot.node_count ?? nodes.length / stride;
|
|
|
|
const byKey = new Map();
|
|
let total = 0;
|
|
for (let i = 0; i < count; i++) {
|
|
const base = i * stride;
|
|
const type = nodeTypes[nodes[base + iType]] ?? "?";
|
|
const name = strings[nodes[base + iName]] ?? "";
|
|
const self = nodes[base + iSelf];
|
|
total += self;
|
|
// Group strings/numbers together — individually they are noise, collectively signal.
|
|
const key = type === "string" || type === "number" || type === "hidden" ? `(${type})` : `${type}:${name}`;
|
|
const acc = byKey.get(key) ?? { bytes: 0, n: 0 };
|
|
acc.bytes += self;
|
|
acc.n++;
|
|
byKey.set(key, acc);
|
|
}
|
|
|
|
const MiB = (b) => (b / 1048576).toFixed(1);
|
|
console.log(`file: ${file}`);
|
|
console.log(`nodes: ${count.toLocaleString()} edges: ${(snap.snapshot.edge_count ?? 0).toLocaleString()}`);
|
|
console.log(`total shallow size: ${MiB(total)} MiB\n`);
|
|
|
|
const top = [...byKey.entries()].sort((a, b) => b[1].bytes - a[1].bytes).slice(0, 35);
|
|
console.log("=== top shallow-size groups ===");
|
|
console.log("bytes(MiB)".padStart(11), "count".padStart(10), " key");
|
|
for (const [key, v] of top) {
|
|
console.log(MiB(v.bytes).padStart(11), String(v.n).padStart(10), ` ${key.slice(0, 90)}`);
|
|
}
|
|
|
|
// Constructor-name rollup ignoring the type prefix, to surface app-level objects.
|
|
const byCtor = new Map();
|
|
for (const [key, v] of byKey) {
|
|
if (key.startsWith("(")) continue;
|
|
const name = key.slice(key.indexOf(":") + 1);
|
|
if (!name) continue;
|
|
const acc = byCtor.get(name) ?? { bytes: 0, n: 0 };
|
|
acc.bytes += v.bytes;
|
|
acc.n += v.n;
|
|
byCtor.set(name, acc);
|
|
}
|
|
console.log("\n=== top named constructors ===");
|
|
for (const [name, v] of [...byCtor.entries()].sort((a, b) => b[1].bytes - a[1].bytes).slice(0, 30)) {
|
|
console.log(MiB(v.bytes).padStart(11), String(v.n).padStart(10), ` ${name.slice(0, 90)}`);
|
|
}
|