Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

entity-card-perf: run latency contracts alone on a ci:ubicloud VM; collect setup garbage before measuring

garrytane67dcc9f88c0
diff --git a/scripts/ci-ubicloud.ts b/scripts/ci-ubicloud.ts
index da3bb01f8c..24ce4da6fe 100755
--- a/scripts/ci-ubicloud.ts
+++ b/scripts/ci-ubicloud.ts
@@ -29,7 +29,7 @@
* pgvector server + PgBouncer per slot, PGLite snapshots), streamed over SSH
* while the checkout uploads. The first VM to
* finish setup runs the machine-level items in order (gitleaks, verify, the
- * serial lane's machine-exclusive files) and then joins the pool. Every other
+ * serial and slow lanes' machine-exclusive files) and then joins the pool. Every other
* test file is an item in one global heaviest-first queue that idle slots pull
* from (scripts/ubicloud/schedule.ts); items run through the same wrappers
* ci:local uses (scripts/ubicloud/ci-item.sh). Durations of every run are
@@ -211,10 +211,11 @@ async function main() {
}
const exclusive = lines(sh("bash", ["scripts/run-serial-tests.sh", "--dry-run-list-exclusive"]));
const serialPool = lines(sh("bash", ["scripts/run-serial-tests.sh", "--dry-run-list"])).filter((f) => !exclusive.includes(f));
+ const slowExclusive = lines(sh("bash", ["scripts/run-slow-tests.sh", "--dry-run-list-exclusive"]));
const inventory: Record<Lane, string[]> = {
unit: lines(sh("bash", ["scripts/run-unit-shard.sh", "--dry-run-list"])),
serial: serialPool,
- slow: lines(sh("bash", ["scripts/run-slow-tests.sh", "--dry-run-list"])),
+ slow: lines(sh("bash", ["scripts/run-slow-tests.sh", "--dry-run-list"])).filter((f) => !slowExclusive.includes(f)),
e2e: e2eFiles,
};
@@ -235,6 +236,7 @@ async function main() {
if (opts.lanes.has("gitleaks")) control.push({ lane: "gitleaks", files: [] });
if (opts.lanes.has("verify")) control.push({ lane: "verify", files: [] });
if (opts.lanes.has("serial") && exclusive.length) control.push({ lane: "serial", files: exclusive });
+ if (opts.lanes.has("slow") && slowExclusive.length) control.push({ lane: "slow", files: slowExclusive });
const totalItems = queue.length + control.reduce((n, c) => n + Math.max(c.files.length, 1), 0);
const estimate = queue.reduce((s, i) => s + i.weight, 0) / 1000;
log(`${totalItems} items (${Object.entries(inventory).filter(([l]) => opts.lanes.has(l)).map(([l, f]) => `${l} ${f.length}`).join(", ")}, control ${control.map((c) => c.lane).join("+") || "none"}); ~${Math.round(estimate)}s of weighted work`);
diff --git a/scripts/run-slow-tests.sh b/scripts/run-slow-tests.sh
index 0e6f929ee5..e727d3c206 100755
--- a/scripts/run-slow-tests.sh
+++ b/scripts/run-slow-tests.sh
@@ -16,13 +16,24 @@ unset DATABASE_URL GBRAIN_DATABASE_URL
unset GBRAIN_HOME
cd "$(dirname "$0")/.."
-# --dry-run-list prints the selection; positional FILE arguments replace
-# discovery (scripts/ci-ubicloud.ts dispatches explicit batches).
-DRY_RUN=0
-if [ "${1:-}" = "--dry-run-list" ]; then
- DRY_RUN=1
- shift
-fi
+# --dry-run-list prints the selection; --dry-run-list-exclusive prints only
+# the machine-exclusive entries. Positional FILE arguments replace discovery
+# (scripts/ci-ubicloud.ts dispatches explicit batches).
+DRY_RUN_MODE=""
+case "${1:-}" in
+ --dry-run-list|--dry-run-list-exclusive) DRY_RUN_MODE="$1"; shift ;;
+esac
+
+# EXCLUSIVE_FILES: latency contracts that must run on an otherwise idle
+# machine, the way GitHub CI runs them on a dedicated perf runner.
+# scripts/ci-ubicloud.ts runs them as control items on a VM with no other
+# work; this script's own lane already runs files one at a time.
+EXCLUSIVE_FILES=(
+ # entity() p99 < 100ms on a 20K-page corpus. Next to 7 heavy items on a
+ # 16-vCPU VM the whole process runs 1.6-2.6x slower (thread CPU time
+ # rises with wall time, so no in-process clock can separate it).
+ "test/entity-card-perf.slow.test.ts"
+)
slow_files=()
if [ "$#" -gt 0 ]; then
@@ -33,10 +44,18 @@ else
done < <(find test -name '*.slow.test.ts' -not -path 'test/e2e/*' | sort)
fi
-if [ "$DRY_RUN" = "1" ]; then
+if [ "$DRY_RUN_MODE" = "--dry-run-list" ]; then
if [ "${#slow_files[@]}" -gt 0 ]; then printf '%s\n' "${slow_files[@]}"; fi
exit 0
fi
+if [ "$DRY_RUN_MODE" = "--dry-run-list-exclusive" ]; then
+ for f in ${slow_files[@]+"${slow_files[@]}"}; do
+ for e in "${EXCLUSIVE_FILES[@]}"; do
+ [ "$f" != "$e" ] || printf '%s\n' "$f"
+ done
+ done
+ exit 0
+fi
. scripts/lib/test-env.sh
receipts_init slow
diff --git a/scripts/ubicloud/README.md b/scripts/ubicloud/README.md
index e4f475ae07..29bc000fbc 100644
--- a/scripts/ubicloud/README.md
+++ b/scripts/ubicloud/README.md
@@ -85,7 +85,9 @@ the VM running the machine-level items below counts only once it joins the
pool.
The first VM to finish setup runs the
machine-level work first: gitleaks, `verify`, then the serial lane's
-machine-exclusive files one at a time with nothing else on that VM. After that
+machine-exclusive files and the slow lane's latency contracts
+(`run-slow-tests.sh --dry-run-list-exclusive`, the files GitHub CI runs on a
+dedicated perf runner) one at a time with nothing else on that VM. After that
it joins the pool. Items run through the `ci:local` wrappers
(`scripts/ubicloud/ci-item.sh`): `run-unit-shard.sh`, `run-serial-tests.sh` and
`run-slow-tests.sh` accept explicit file arguments for this purpose, and
diff --git a/test/entity-card-perf.slow.test.ts b/test/entity-card-perf.slow.test.ts
index 134fa5da06..a3f926033a 100644
--- a/test/entity-card-perf.slow.test.ts
+++ b/test/entity-card-perf.slow.test.ts
@@ -48,6 +48,7 @@
*/
import { describe, it, expect, beforeAll, afterAll } from 'bun:test';
+import { heapSize } from 'bun:jsc';
import { PGLiteEngine } from '../src/core/pglite-engine.ts';
import { buildEntityCard } from '../src/core/verbs/entity-card.ts';
import {
@@ -90,6 +91,22 @@ const HUB_RATIO_CEILING = 8;
// Catastrophe backstop only; the ratio is the gate.
const HUB_ABSOLUTE_CEILING_MS = 1000 * (Number(process.env.GBRAIN_TEST_PERF_BUDGET_MULTIPLIER) || 1);
+interface Sample { name: string; wall: number; cpu: number; heapDeltaMB: number }
+
+/** One timed call, with the thread's CPU time and JS heap change (a large change means a GC ran inside it). */
+async function sample(name: string, fn: () => Promise<unknown>): Promise<Sample> {
+ const h0 = heapSize(), c0 = process.threadCpuUsage(), t0 = performance.now();
+ await fn();
+ const wall = performance.now() - t0, c = process.threadCpuUsage(c0);
+ return { name, wall, cpu: (c.user + c.system) / 1000, heapDeltaMB: (heapSize() - h0) / 2 ** 20 };
+}
+
+/** The five slowest samples for the log: cpu well under wall is scheduler wait, a heap jump is a GC, cpu≈wall with neither is a slower CPU. */
+function slowest(samples: Sample[]): string {
+ return [...samples].sort((a, b) => b.wall - a.wall).slice(0, 5)
+ .map(s => `${s.name} wall=${s.wall.toFixed(1)} cpu=${s.cpu.toFixed(1)} heapΔ=${s.heapDeltaMB.toFixed(1)}MB`).join(' | ');
+}
+
function percentile(sorted: number[], p: number): number {
const idx = Math.min(sorted.length - 1, Math.ceil((p / 100) * sorted.length) - 1);
return sorted[Math.max(0, idx)];
@@ -210,14 +227,15 @@ describe('entity card p99 latency gate', () => {
await buildEntityCard(engine, 'default', names[i % names.length], { remote: true });
}
- const samples: number[] = [];
+ Bun.gc(true);
+ const runs: Sample[] = [];
for (let i = 0; i < MEASURED; i++) {
const name = names[(i * 13) % names.length];
- const t0 = performance.now();
- await buildEntityCard(engine, 'default', name, { remote: true });
- samples.push(performance.now() - t0);
+ runs.push(await sample(name, () => buildEntityCard(engine, 'default', name, { remote: true })));
}
- samples.sort((a, b) => a - b);
+ // eslint-disable-next-line no-console
+ console.log(`[entity-card-perf] slowest: ${slowest(runs)}`);
+ const samples = runs.map(r => r.wall).sort((a, b) => a - b);
const p50 = percentile(samples, 50);
const p99 = percentile(samples, 99);
@@ -250,13 +268,15 @@ describe('entity verb with referenced_by (entity recall)', () => {
const names: string[] = [];
for (let i = 0; i < TARGET_ENTITIES; i++) names.push(`Target Person ${i}`, `tp${i}`, `zzz-absent-${i}`);
for (let i = 0; i < WARMUP; i++) await buildEntityCard(engine, 'default', names[i % names.length], opts);
- const samples: number[] = [];
+ Bun.gc(true);
+ const runs: Sample[] = [];
for (let i = 0; i < MEASURED; i++) {
- const t0 = performance.now();
- await buildEntityCard(engine, 'default', names[(i * 13) % names.length], opts);
- samples.push(performance.now() - t0);
+ const name = names[(i * 13) % names.length];
+ runs.push(await sample(name, () => buildEntityCard(engine, 'default', name, opts)));
}
- samples.sort((a, b) => a - b);
+ // eslint-disable-next-line no-console
+ console.log(`[entity-recall-perf] slowest: ${slowest(runs)}`);
+ const samples = runs.map(r => r.wall).sort((a, b) => a - b);
const p50 = percentile(samples, 50);
const p99 = percentile(samples, 99);
// eslint-disable-next-line no-console
diff --git a/test/scripts/ci-ubicloud-schedule.test.ts b/test/scripts/ci-ubicloud-schedule.test.ts
index 8f2a1f6fb8..afb4cde330 100644
--- a/test/scripts/ci-ubicloud-schedule.test.ts
+++ b/test/scripts/ci-ubicloud-schedule.test.ts
@@ -165,6 +165,14 @@ describe("explicit-file seams in the ci:local wrappers", () => {
expect(list("run-slow-tests.sh", "--dry-run-list", "test/x.slow.test.ts")).toEqual(["test/x.slow.test.ts"]);
});
+ it("run-slow-tests.sh exposes its exclusive subset of discovery", () => {
+ const exclusive = list("run-slow-tests.sh", "--dry-run-list-exclusive");
+ expect(exclusive).toContain("test/entity-card-perf.slow.test.ts");
+ const all = list("run-slow-tests.sh", "--dry-run-list");
+ for (const file of exclusive) expect(all).toContain(file);
+ expect(list("run-slow-tests.sh", "--dry-run-list-exclusive", "test/x.slow.test.ts")).toEqual([]);
+ });
+
it("run-serial-tests.sh lists positional files and exposes its exclusive subset", () => {
expect(list("run-serial-tests.sh", "--dry-run-list", "test/x.serial.test.ts")).toEqual(["test/x.serial.test.ts"]);
const exclusive = list("run-serial-tests.sh", "--dry-run-list-exclusive");