Skip to content

Latest commit

 

History

History
74 lines (57 loc) · 3.72 KB

performance.md

File metadata and controls

74 lines (57 loc) · 3.72 KB

Performance: ts-morph engine vs native TypeScript 7.1 engine

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.

Methodology

  • 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's src/ (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).

Demo corpus — full build (parse → DSL → SVG), median ms

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

Demo corpus — parse stage only, median ms

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.

Larger corpus (repo src/) — full build, median ms

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.

Where the time goes

  • 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.

Caveats

  • 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.

History

  • Engine swap decision and alternatives: ADR-0001
  • PRs: #184 (engine swap), #185 (reusable engine), #186 (checker memoization), #187 (CLI DSL-only mode)