// Two export baselines side by side (R4.6, E3 and E4): the TypeScript engine's // build and the Rust session's build, same reports, same harness, same host. // Per engine and report: the median export time (page clock, click to the // PDF blob) and its ratio (E3: Rust ≤ 1.2 × TS in Chromium on demo and L), // the outcome (E4: L completes everywhere the TS did, CAP completes within // the harness ceiling), the content-process RSS peak and the settled growth // (after − before, forced GC in Chromium), the file size, and the phases: // before the first raster, the raster phase (first `toBlob` start to the last // `toBlob` end), the tail to the PDF blob, plus the Rust driver's own split // (core calls, rasteriser awaits) when the build published it. // // node scripts/browser/compare-exports.mjs import { readFileSync } from 'node:fs' const [tsPath, r4Path] = process.argv.slice(2) if (!tsPath || !r4Path) { console.error('usage: compare-exports.mjs ') process.exit(2) } const load = (path) => JSON.parse(readFileSync(path, 'utf8')) const runsOf = (result) => result.export?.runs ?? result.runs ?? [] const median = (values) => { const sorted = values.filter((v) => v != null).sort((a, b) => a - b) if (!sorted.length) return null return sorted[Math.floor(sorted.length / 2)] } const mib = (bytes) => (bytes == null ? '' : (bytes / 1024 / 1024).toFixed(0)) const ms = (value) => (value == null ? '' : Math.round(value).toString()) const ratio = (a, b) => (a == null || b == null || !b ? '' : (a / b).toFixed(2)) function group(runs) { const groups = new Map() for (const run of runs) { const key = `${run.engine}|${run.report}` if (!groups.has(key)) groups.set(key, []) groups.get(key).push(run) } return groups } function summary(runs) { const done = runs.filter((r) => r.outcome === 'downloaded') const outcomes = runs.map((r) => r.outcome) return { outcome: [...new Set(outcomes)].join(', '), exportMs: median(done.map((r) => r.exportMs)), pdfBytes: median(done.map((r) => r.pdfBytes)), peakContent: median(runs.map((r) => r.rssPeakContentBytes)), growth: median( done.map((r) => r.after && r.before ? r.after.rssContentBytes - r.before.rssContentBytes : null, ), ), heapAfter: median(done.map((r) => r.after?.jsHeapUsedBytes ?? null)), headMs: median(done.map((r) => r.phases?.headMs ?? null)), rasterPhaseMs: median(done.map((r) => r.phases?.rasterPhaseMs ?? null)), tailMs: median(done.map((r) => r.phases?.tailMs ?? null)), coreMs: median(done.map((r) => r.phases?.driver?.coreMs ?? null)), rasterSumMs: median(done.map((r) => r.phases?.driver?.rasterMs ?? null)), rasters: median(done.map((r) => r.rasters?.count ?? null)), stoppedAt: median(runs.map((r) => r.stoppedAtBytes ?? null)), rastersBeforeEnd: median(runs.map((r) => r.rastersBeforeEnd ?? null)), } } const ts = group(runsOf(load(tsPath))) const r4 = group(runsOf(load(r4Path))) const keys = [...new Set([...ts.keys(), ...r4.keys()])] console.log('## Time (median of the runs, page clock, click to the PDF blob)\n') console.log( '| Engine | Report | TS outcome | Rust outcome | TS ms | Rust ms | Rust / TS | TS PDF | Rust PDF |', ) console.log('|---|---|---|---|---|---|---|---|---|') for (const key of keys) { const [engine, report] = key.split('|') const a = summary(ts.get(key) ?? []) const b = summary(r4.get(key) ?? []) console.log( `| ${engine} | ${report} | ${a.outcome} | ${b.outcome} | ${ms(a.exportMs)} | ${ms(b.exportMs)} | ${ratio(b.exportMs, a.exportMs)} | ${a.pdfBytes ?? ''} | ${b.pdfBytes ?? ''} |`, ) } console.log('\n## Memory (content-process RSS, MiB; growth = settled after − settled before)\n') console.log( '| Engine | Report | TS peak | Rust peak | TS growth | Rust growth | TS heap after | Rust heap after | Rust rasters before the ceiling |', ) console.log('|---|---|---|---|---|---|---|---|---|') for (const key of keys) { const [engine, report] = key.split('|') const a = summary(ts.get(key) ?? []) const b = summary(r4.get(key) ?? []) console.log( `| ${engine} | ${report} | ${mib(a.peakContent)} | ${mib(b.peakContent)} | ${mib(a.growth)} | ${mib(b.growth)} | ${mib(a.heapAfter)} | ${mib(b.heapAfter)} | ${b.rastersBeforeEnd ?? ''} |`, ) } console.log( '\n## Phases (ms; head = click to the first raster, raster phase = first toBlob start to last toBlob end, tail = last raster to the PDF blob; core / raster = the Rust driver\'s User Timing)\n', ) console.log( '| Engine | Report | TS head | TS raster phase | TS tail | Rust head | Rust raster phase | Rust tail | Rust core calls | Rust raster awaits | rasters |', ) console.log('|---|---|---|---|---|---|---|---|---|---|---|') for (const key of keys) { const [engine, report] = key.split('|') const a = summary(ts.get(key) ?? []) const b = summary(r4.get(key) ?? []) console.log( `| ${engine} | ${report} | ${ms(a.headMs)} | ${ms(a.rasterPhaseMs)} | ${ms(a.tailMs)} | ${ms(b.headMs)} | ${ms(b.rasterPhaseMs)} | ${ms(b.tailMs)} | ${ms(b.coreMs)} | ${ms(b.rasterSumMs)} | ${b.rasters ?? a.rasters ?? ''} |`, ) }