Skip to content

fix(ui): cache complex Unicode cluster widths - #800

Merged
benvinegar merged 1 commit into
mainfrom
fix/complex-cluster-width-cache
Aug 18, 2026
Merged

fix(ui): cache complex Unicode cluster widths#800
benvinegar merged 1 commit into
mainfrom
fix/complex-cluster-width-cache

Conversation

@benvinegar

Copy link
Copy Markdown
Member

Summary

  • segment composition-sensitive text once instead of measuring the full line with string-width
  • cache exact multi-scalar cluster widths with a 256-entry / 64-code-unit FIFO bound
  • add cache-bound and Unicode-parity coverage plus a patch changeset

Validation

  • bun test src/ui/lib/ui-lib.test.ts
  • bun run typecheck
  • bun run lint
  • bun run bench:terminal-width — checksum remains 196000; complex-cluster hot path measured ~28.5× faster locally

bun test still has unrelated fresh-main failures in review-conformance/diff pairing plus Playwright test discovery.

This PR description was generated by Pi using gpt-5.6-terra

@vercel

vercel Bot commented Aug 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
hunk-web Ignored Ignored Aug 18, 2026 2:30am

Request Review

@greptile-apps

greptile-apps Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR optimizes complex Unicode width measurement by segmenting composition-sensitive text once and caching exact multi-scalar cluster widths.

  • Adds a 256-entry FIFO cache with a 64-code-unit key limit.
  • Preserves string-width parity while avoiding repeated full-line segmentation.
  • Adds cache-boundary and Unicode-parity tests plus benchmark documentation and a patch changeset.

Confidence Score: 5/5

The PR appears safe to merge with no concrete blocking or non-blocking defects identified.

The bounded cache preserves exact cluster widths, enforces its intended entry and key-size limits, and the new segmented traversal remains equivalent to the existing string-width behavior for reachable sanitized text.

Important Files Changed

Filename Overview
src/ui/lib/text.ts Adds the bounded cluster-width cache and routes composition-sensitive width calculation through a single grapheme traversal without an identified correctness regression.
src/ui/lib/ui-lib.test.ts Adds focused coverage for FIFO eviction, oversized-key rejection, cache churn, and Unicode width parity.
benchmarks/terminal-width.ts Updates benchmark terminology to describe the cached complex-cluster path.
benchmarks/README.md Updates terminal-width benchmark documentation to reflect cached cluster measurement.
.changeset/swift-clusters-measure.md Records the Unicode width-measurement performance improvement as a patch release.

Reviews (1): Last reviewed commit: "fix(ui): cache complex cluster widths" | Re-trigger Greptile

@benvinegar
benvinegar merged commit 20c1295 into main Aug 18, 2026
13 checks passed
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.

1 participant