// Survey §11 item 6: does a row shape that allocates less change the young-generation GC that
// lands inside a clear performed right after creation (§10.6: 22–35 ms of scavenge in the
// shipped runtime's immediate clear)? The DOM-floor page's bookkeeping shapes (none / current
// / folded, audit-state-tech-fold.mjs) create 10,000 rows and clear them in the same task,
// under a CDP trace with the v8.gc category; the scavenge time and count inside the clear
// window and the creation window are compared per shape. Fresh page per sample. Run from the
// repository root after `npm ci` in e2e/, with no other performance driver running:
// node scripts/audit-state-tech-gcshape.mjs [--samples N]
import { readFile, writeFile, mkdir } from 'node:fs/promises';
import { join, resolve } from 'node:path';
import { createRequire } from 'node:module';
import { spawn, execFileSync } from 'node:child_process';
import { cpus } from 'node:os';
import { startTrace, stopTrace, summarize } from './research/cdpTrace.mjs';
const root = resolve(import.meta.dirname, '..');
const require = createRequire(join(root, 'e2e/package.json'));
const { chromium } = require('@playwright/test');
const outDir = join(root, 'docs/research/state-next');
await mkdir(outDir, { recursive: true });
const N = process.argv.includes('--samples') ? Number(process.argv[process.argv.indexOf('--samples') + 1]) : 5;
const port = 4306;
const url = `http://127.0.0.1:${port}/packages/state/__e2e__/benchmark/index.html`;
const pageScript = await readFile(join(root, 'scripts/research/domFloorPage.js'), 'utf8');
const domHtml = '