co-mono/packages
nathyong 6e4270a286 tui: only check for emojis in visibleWidth when necessary
The initial render of a session, and any re-draws caused by terminal
resizing are noticeably slow, especially on conversations with 20+
turns and many tool calls.

From profiling with `bun --cpu-prof` (available since bun 1.3.2), the
majority of the rendering (90%) is spent on detection of emojis in the
string-width library, running the expensive `/\p{RGI_Emoji}$/v`
regular expression on every individual grapheme cluster in the entire
scrollback. I believe it essentially expands to a fixed search against
every possible emoji sequence, hence the amount of CPU time spent in it.

This change replaces the `stringWidth` from string-width with a
`graphemeWidth` function that performs a similar check, but avoids
running the `/\p{RGI_Emoji}$/v` regex for emoji detection unless it
contains codepoints that could be emojis.

The `visibleWidth` function also has two more optimisations:
- Short-circuits string length detection for strings that are entirely
  printable ASCII characters
- Adds a cache for non-ASCII segments to avoid recomputing string length
  when resizing
2026-01-02 01:56:11 +01:00
..
agent Add setEditorText/getEditorText to hook UI context, improve custom() API 2026-01-01 00:04:56 +01:00
ai WIP: Rewrite export-html with tree sidebar, client-side rendering 2026-01-01 03:36:47 +01:00
coding-agent Update docs for ctx.ui.editor() and handoff example 2026-01-02 01:26:21 +01:00
mom Update mom CHANGELOG.md for unreleased changes since v0.30.2 2025-12-31 00:07:49 +01:00
pods Fix pods CLI: remove reference to non-existent stopAllModels 2025-12-30 22:42:25 +01:00
tui tui: only check for emojis in visibleWidth when necessary 2026-01-02 01:56:11 +01:00
web-ui Minor README update 2025-12-31 00:03:50 +01:00