Skip to content

bench: add vitest benchmarks for diff, display lines, and TUI rendering#98

Merged
watany-dev merged 5 commits into
mainfrom
claude/perf-optimization-benchmarks-kfci5o
Jun 13, 2026
Merged

bench: add vitest benchmarks for diff, display lines, and TUI rendering#98
watany-dev merged 5 commits into
mainfrom
claude/perf-optimization-benchmarks-kfci5o

Conversation

@watany-dev

Copy link
Copy Markdown
Owner

Covers computeSimpleDiff worst cases, buildDisplayLines cold/warm cache,
and PullRequestDetail keystroke/scroll latency via ink-testing-library.

https://claude.ai/code/session_01HQLaGAamsw5NVDERVKR5Yt

claude added 5 commits June 13, 2026 01:21
Covers computeSimpleDiff worst cases, buildDisplayLines cold/warm cache,
and PullRequestDetail keystroke/scroll latency via ink-testing-library.

https://claude.ai/code/session_01HQLaGAamsw5NVDERVKR5Yt
…teSimpleDiff

The greedy diff only uses matches within 5 lines, but indexOf scanned to
the end of the array, making rewrites O(n^2). Scanning just the window is
semantically identical and linear.

Benchmark (mean): fully rewritten 2000-line file 44.9ms -> 0.085ms,
3000-line file with 10 edit blocks 77.3ms -> 0.23ms.

https://claude.ai/code/session_01HQLaGAamsw5NVDERVKR5Yt
- Enrich cached diff lines with filePath/diffKey once instead of spreading
  every line on every buildDisplayLines call
- Skip inline-thread matching entirely when no inline comments exist
- Count lines without split("\n") on the warm-cache path and in the
  t-key handler (countLines helper)
- Hoist the separator string constant
- Render rows through a memoized DiffRow with a single top-level Text;
  stable line identity from the cache lets unchanged rows skip
  reconciliation on cursor moves

Benchmark (mean): buildDisplayLines 20 files x 400 lines warm cache
3.8ms -> 0.42ms, cold cache 81.9ms -> 1.6ms.

https://claude.ai/code/session_01HQLaGAamsw5NVDERVKR5Yt
…ct build

string-width@8.1.1 runs grapheme segmentation plus an RGI emoji regex per
cluster even for plain ASCII; profiling showed ~64% of keystroke render
time there. Patches:
- string-width: fast path returning length for printable-ASCII strings
- ink render-node-to-output: reuse the memoized measureText cache instead
  of re-running widestLine on every frame
- ink output: cache per-character widths (glyphs repeat across frames)

build.ts now inlines NODE_ENV=production so the bundled CLI uses the
production react-reconciler instead of deciding at runtime (users rarely
set NODE_ENV); bundle shrinks 1224.6KB -> 1087.4KB.

Keystroke render in PullRequestDetail (10 files x 200 lines):
33.8ms -> 4.2ms per keystroke.

https://claude.ai/code/session_01HQLaGAamsw5NVDERVKR5Yt
- Register string-width/ink patchedDependencies and add bun run bench
- Update overrides (fast-xml-parser, fast-xml-builder, ws, postcss,
  esbuild) and bump vitest to ^4.1.0 to clear bun audit advisories
- Allow esbuild in minimumReleaseAgeExcludes (fix is younger than 7 days)

https://claude.ai/code/session_01HQLaGAamsw5NVDERVKR5Yt
@watany-dev watany-dev merged commit b7007cb into main Jun 13, 2026
7 checks passed
@watany-dev watany-dev deleted the claude/perf-optimization-benchmarks-kfci5o branch June 13, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants