bench: add vitest benchmarks for diff, display lines, and TUI rendering#98
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Covers computeSimpleDiff worst cases, buildDisplayLines cold/warm cache,
and PullRequestDetail keystroke/scroll latency via ink-testing-library.
https://claude.ai/code/session_01HQLaGAamsw5NVDERVKR5Yt