Measured comparison of the old ts-morph-based engine (TS 5.4.2 JS compiler, bundled)
against the current native engine (TS 7.1, typescript/sync), including the
reusable-engine option and per-snapshot checker memoization.
- Same machine, Node v24, sequential runs; medians of 10 runs after one warmup call. "Cold" = the very first call in a fresh process (includes engine startup).
- Corpora:
src/demo(10 files; 13 classes, 11 interfaces, 5 type aliases, 1 enum) and the repo'ssrc/(26–27 files). Declaration counts and DSL byte counts were verified identical across engines. - Stages measured separately: parse (
parseProject), nomnoml DSL, mermaid DSL, SVG render (renderNomnomlSVG, nomnoml 1.7.0 — unchanged between engines). - Reproduce:
npm run build && node scripts/bench.cjs <label> [glob] [per-call|reuse](JSON output; run against any built checkout to compare).
| Engine / mode | default | associations | cold first call |
|---|---|---|---|
| ts-morph 22 (TS 5.4.2) | 792 | 744 | 1582 |
| native 7.1, per-call | 195 | 210 | 283 |
| native 7.1, reused engine | 24.5 | 32.9 | 122 |
| Engine / mode | default | associations |
|---|---|---|
| ts-morph 22 | 771 | 706 |
| native 7.1, per-call | 171 | 175 |
| native 7.1, reused+memo | 3.4 | 3.9 |
DSL-only output (parse + DSL, no SVG render) is ~4 ms with a reused engine — roughly 200x faster than the old engine's parse alone.
| Engine / mode | default | associations |
|---|---|---|
| ts-morph 22 (26 files) | 1068 | 1015 |
| native 7.1, reused (27 files*) | 42 | 56 |
* the current source tree contains one additional file (checker-cache.ts);
the difference is negligible at this scale.
- CLI module loading (~141 ms cold):
typescript/sync's generated API graph costs ~119 ms to compile, yargs ~29 ms, chalk ~11 ms, nomnoml ~9 ms. The bin entry enables Node's V8 compile cache (module.enableCompileCache(), Node ≥ 22.1) before loading the CLI, cutting warm CLI runs by ~110 ms (measured 0.45 s → 0.34 s wall). - Per-call usage is dominated by engine creation (~150 ms: program construction, lib parsing, checker init). Process spawn is only ~10 ms of that. This floor is inherent to building a checked program; reuse is the answer for repeated work.
- Reused-engine parses are a few ms: checker queries are memoized per snapshot
(
src/core/parser/checker-cache.ts), eliminating the bulk of IPC round-trips. - SVG rendering (nomnoml, ~20–45 ms) is unchanged third-party code and dominates the reused full-build time. DSL-only paths skip it entirely.
- The native checker itself is ~10x faster than the JS compiler on large projects; at demo scale the wins above are mostly initialization and IPC, not raw checking.
- Absolute numbers are machine-dependent; the relative speedups are the point.
- Small corpora understate the native checker's advantage on large codebases.
- Reused engines are point-in-time snapshots: recreate them after source files change.
- Engine swap decision and alternatives: ADR-0001
- PRs: #184 (engine swap), #185 (reusable engine), #186 (checker memoization), #187 (CLI DSL-only mode)