Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Wave B lane 1d bench: reference page above the single-string ceiling, one small write per event-loop turn, page-scoped text counts

garrytan1c7205277c15
diff --git a/scripts/bench-large-pages.ts b/scripts/bench-large-pages.ts
index 7abfc5df5d..cd822be9ee 100644
--- a/scripts/bench-large-pages.ts
+++ b/scripts/bench-large-pages.ts
@@ -6,18 +6,19 @@
* - `ingest_ms`: wall time of the streamed import (pass 1, pass 2, staging,
* flip, projection), no provider calls.
* - `rss`: peak RSS of a fresh child process ingesting `--size` and one
- * ingesting 10 MiB through the same path, and their difference (the slope:
- * ingest memory must not grow with the page).
- * - `rows`: segment texts, live manifest rows and chunk rows the ingest wrote.
- * - `append_10kb`: time and rows written by re-importing the file with 10 KB
+ * ingesting a page 2 MiB over PAGE_MAX_BYTES through the same path, and
+ * their difference (the slope: ingest memory must not grow with the page).
+ * - `rows`: distinct segment texts and manifest rows of the live generation, and live chunk rows.
+ * - `append_10kb`: time, and the manifest and chunk rows the new generation staged, of re-importing the file with 10 KB
* appended (only the tail should be restaged).
* - `concurrent_small_put`: latency of small page writes (the put_page import
- * core, `importFromContent`) issued back to back while the large ingest runs.
+ * core, `importFromContent`) issued one per event-loop turn, as separate
+ * requests arrive, while the large ingest runs.
*
* Run it under a memory cap so a regression fails instead of swapping:
* sudo systemd-run --scope -p MemoryMax=3G bun scripts/bench-large-pages.ts --size 100MB
* sudo systemd-run --scope -p MemoryMax=3G env DATABASE_URL=postgresql://... bun scripts/bench-large-pages.ts --size 100MB --engine postgres
- * Flags: --size <N>[KB|MB|GB] (default 100MB), --engine pglite|postgres (default pglite; postgres reads DATABASE_URL), --json.
+ * Flags: --size <N>[KB|MB|GB] (default 100MB; above PAGE_MAX_BYTES, where the streamed path starts), --engine pglite|postgres (default pglite; postgres reads DATABASE_URL), --json.
*/
import { spawnSync } from 'node:child_process';
import { appendFileSync, mkdtempSync, rmSync, statSync, writeFileSync } from 'node:fs';
@@ -26,6 +27,7 @@ import { join } from 'node:path';
import type { BrainEngine } from '../src/core/engine.ts';
import { importFromContent } from '../src/core/import-file.ts';
import { readPageBodyPolicy } from '../src/core/page-body/limits.ts';
+import { PAGE_MAX_BYTES } from '../src/core/page-size-policy.ts';
import { importStreamedMarkdownFile } from '../src/core/page-body/streamed-import.ts';
import { conversationBody, conversationPage } from '../test/helpers/conversation-page.ts';
@@ -72,7 +74,7 @@ async function pageRows(engine: BrainEngine) {
const generation = Number(page.body_generation);
return {
generation,
- texts: await count(engine, 'SELECT count(*) AS n FROM page_segment_texts WHERE source_id=$1', ['default']),
+ texts: await count(engine, 'SELECT count(DISTINCT sha256) AS n FROM page_body_manifest WHERE page_id=$1 AND gen_from<=$2 AND (gen_to IS NULL OR gen_to>$2)', [id, generation]),
manifest: await count(engine, 'SELECT count(*) AS n FROM page_body_manifest WHERE page_id=$1 AND gen_from<=$2 AND (gen_to IS NULL OR gen_to>$2)', [id, generation]),
manifestAtGeneration: await count(engine, 'SELECT count(*) AS n FROM page_body_manifest WHERE page_id=$1 AND gen_from=$2', [id, generation]),
chunks: await count(engine, 'SELECT count(*) AS n FROM content_chunks WHERE page_id=$1 AND retired_generation IS NULL', [id]),
@@ -116,6 +118,7 @@ async function main(): Promise<void> {
const size = parseSize(arg('--size', '100MB'));
const kind = arg('--engine', 'pglite');
if (process.argv.includes('--child')) return child(arg('--child', ''), kind);
+ if (size <= PAGE_MAX_BYTES) throw new Error(`--size ${size} is not above PAGE_MAX_BYTES (${PAGE_MAX_BYTES}); smaller files take the single-string import.`);
const dir = mkdtempSync(join(tmpdir(), 'gbrain-bench-large-'));
const engine = await openEngine(kind, dir);
@@ -132,6 +135,7 @@ async function main(): Promise<void> {
const t0 = performance.now();
await importFromContent(engine, `bench/small-${i % 50}`, `---\ntitle: Small ${i}\ntype: note\n---\n\nA short note, revision ${i}.\n`, { sourceId: 'default', noEmbed: true });
latencies.push(performance.now() - t0);
+ await new Promise(resolve => setImmediate(resolve));
}
})();
const t0 = performance.now();
@@ -149,16 +153,16 @@ async function main(): Promise<void> {
latencies.sort((a, b) => a - b);
const pct = (p: number) => latencies.length ? round(latencies[Math.min(latencies.length - 1, Math.floor(latencies.length * p))]!) : null;
- const reference = join(dir, 'page-10mib.md');
+ const reference = join(dir, 'page-reference.md');
writeFileSync(file, conversationPage(size, { seed: 1 }));
- writeFileSync(reference, conversationPage(10 * 1024 * 1024, { seed: 1 }));
+ writeFileSync(reference, conversationPage(PAGE_MAX_BYTES + 2 * 1024 * 1024, { seed: 1 }));
const rssLarge = childRss(file, kind);
const rssSmall = childRss(reference, kind);
const report = {
engine: kind, size_bytes: statSync(file).size, ingest_ms: round(ingestMs),
- rss: { peak_bytes: rssLarge, peak_10mib_bytes: rssSmall, slope_bytes: rssLarge - rssSmall },
+ rss: { peak_bytes: rssLarge, peak_reference_bytes: rssSmall, slope_bytes: rssLarge - rssSmall },
rows: { texts: rows.texts, manifest: rows.manifest, chunks: rows.chunks },
- append_10kb: { ms: round(appendMs), texts: appended.texts - rows.texts, manifest: appended.manifestAtGeneration, chunks: appended.chunksAtGeneration },
+ append_10kb: { ms: round(appendMs), manifest: appended.manifestAtGeneration, chunks: appended.chunksAtGeneration },
concurrent_small_put: { writes: latencies.length, p50_ms: pct(0.5), p95_ms: pct(0.95), max_ms: pct(1) },
};
if (process.argv.includes('--json')) process.stdout.write(JSON.stringify(report) + '\n');