perf(research): add compact replay projections and representative profiling

This commit is contained in:
Boki 2026-10-23 10:42:31 -04:00
parent 19e9dad68b
commit e3bd722e31
21 changed files with 2830 additions and 130 deletions

View file

@ -5,6 +5,8 @@
* bun run scripts/benchmark-research.ts --measure --large # additionally 100k (quadratic queue)
* bun run scripts/benchmark-research.ts --session # canonical pull-session self-test
* bun run scripts/benchmark-research.ts --session --measure # 1k/10k bars, actual TS decisions
* bun run scripts/benchmark-research.ts --session --measure --profile=sparse --bars=10000
* bun run scripts/benchmark-research.ts --session --measure --profile=all --format=both --bars=10000
* Build workspace libraries/config and the local engine first. JSON stdout; diagnostics stderr.
*/
import { createHash } from 'node:crypto';
@ -336,6 +338,77 @@ export function verifyRepeats(
}
}
/** Explicit benchmark selections, not application dataset/input limits. */
export function parseBenchmarkArguments(args: string[]) {
const options = {
session: false,
measured: false,
large: false,
selfTest: false,
profile: 'turnover' as 'none' | 'sparse' | 'turnover' | 'all',
resultFormat: 'trace' as 'trace' | 'projection' | 'both',
totalBars: undefined as number | undefined,
};
const seen = new Set<string>();
for (const argument of args) {
const [flag, value] = argument.split('=');
if (!flag || seen.has(flag)) {
throw new Error('Duplicate or invalid benchmark flag');
}
seen.add(flag);
switch (flag) {
case '--session':
options.session = true;
break;
case '--measure':
options.measured = true;
break;
case '--large':
options.large = true;
break;
case '--self-test':
options.selfTest = true;
break;
case '--profile':
if (!['none', 'sparse', 'turnover', 'all'].includes(value ?? '')) {
throw new Error('Unknown benchmark profile');
}
options.profile = value as typeof options.profile;
break;
case '--format':
if (!['trace', 'projection', 'both'].includes(value ?? '')) {
throw new Error('Unknown benchmark result format');
}
options.resultFormat = value as typeof options.resultFormat;
break;
case '--bars':
if (!['1000', '10000', '100000'].includes(value ?? '')) {
throw new Error('Benchmark --bars must be1000,10000 or100000');
}
options.totalBars = Number(value);
break;
default:
throw new Error('Unknown benchmark flag');
}
if (!['--profile', '--format', '--bars'].includes(flag) && value !== undefined) {
throw new Error('Boolean benchmark flags do not accept values');
}
if (argument.split('=').length > 2) {
throw new Error('Invalid benchmark flag value');
}
}
if ((options.large && !options.measured) || (options.selfTest && options.measured)) {
throw new Error('Use no flags/--self-test, --measure, or --measure --large');
}
if (!options.session && ['--profile', '--format', '--bars'].some(flag => seen.has(flag))) {
throw new Error('Profile, format and bar selections require --session');
}
if (options.totalBars !== undefined && (!options.measured || options.large)) {
throw new Error('--bars requires --measure and cannot be combined with --large');
}
return options;
}
async function main(args: string[]) {
if (args[0] === '--session-child') {
const { sessionChild } = await import('./benchmark-replay');
@ -346,25 +419,23 @@ async function main(args: string[]) {
process.stdout.write(JSON.stringify(await child(JSON.parse(args[1] ?? ''))) + '\n');
return;
}
if (
args.some(a => !['--self-test', '--measure', '--large', '--session'].includes(a)) ||
(args.includes('--large') && !args.includes('--measure')) ||
(args.includes('--self-test') && args.includes('--measure'))
) {
throw new Error(
'Use no flags/--self-test, --measure, or --measure --large; optionally --session'
);
}
const selection = parseBenchmarkArguments(args);
const metadata = identity(); // Excluded from workload timings.
const measured = args.includes('--measure');
if (args.includes('--session')) {
const measured = selection.measured;
if (selection.session) {
const { sessionBenchmark } = await import('./benchmark-replay');
await sessionBenchmark(
root,
fileURLToPath(import.meta.url),
metadata,
measured,
args.includes('--large')
selection.large,
{
profiles:
selection.profile === 'all' ? ['none', 'sparse', 'turnover'] : [selection.profile],
resultFormat: selection.resultFormat,
totalBars: selection.totalBars,
}
);
return;
}