Skip to content

perf: keep the TUI off the status line render path - #575

Merged
sirmalloc merged 2 commits into
sirmalloc:mainfrom
durandom:lazy-load-tui
Sep 18, 2026
Merged

sirmalloc merged 2 commits into
sirmalloc:mainfrom
durandom:lazy-load-tui

Conversation

@durandom

@durandom durandom commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Problem

Claude Code re-runs the status line command every couple of seconds for as long as a session is open, so this binary's module load time is paid continuously rather than once at startup.

src/ccstatusline.ts imports runTUI statically:

import { runTUI } from './tui';

That pulls ink, React and yoga-layout into the render path even though rendering never touches any of them — they are only needed for the interactive config editor.

What I tried first, and why it wasn't enough

Making the import dynamic on its own changes nothing measurable: bun build --outfile cannot code-split, so the whole graph still ends up in one file and still gets parsed on every render. I measured 255 ms vs 250 ms, i.e. noise.

The win only appears when the build actually splits. --splitting --format=esm --outdir=dist moves the TUI into its own chunk and shrinks the entry from 3.34 MB to 21 KB.

Result

M-series Mac, 20 runs per data point, a real Claude Code payload piped to stdin:

ms/render
before 238, 237, 238
after 226, 222, 220

About 7%. Modest, but it is paid on every render for the whole session, and the rendered output is byte-identical (diff on the ANSI output).

Verification

  • bun run lint (tsc + eslint) clean.
  • Rendered output byte-identical before/after.
  • Interactive TUI smoke-tested under a pty: same first frame, no module resolution errors.
  • Built output runs under node as well as bun.

The non-obvious part

scripts/replace-version.ts had to change too. With splitting, the __PACKAGE_VERSION__ placeholder lands in a chunk rather than in dist/ccstatusline.js, so patching only the entry would have silently shipped an unreplaced placeholder. It now patches every emitted script and exits non-zero if it finds none, so this cannot regress quietly.

Packaging is unaffected: files is already dist/, and bin/main/exports keep pointing at dist/ccstatusline.js.

https://claude.ai/code/session_01Jy7HKv8er6ZiodbjFeped2

durandom and others added 2 commits September 4, 2026 18:53
Claude Code re-runs this binary every couple of seconds for as long as a
session is open, so module load time is paid continuously rather than once.

src/ccstatusline.ts imports runTUI statically, which pulls ink, React and
yoga-layout into the render path even though rendering never touches them.
Making that import dynamic is not enough on its own: --outfile cannot split,
so the whole graph still gets parsed. Building with --splitting moves the TUI
into its own chunk and shrinks the entry from 3.34 MB to 21 KB.

Measured on an M-series Mac, 20 runs per data point, real payload piped in:

  before  238, 237, 238 ms/render
  after   226, 222, 220 ms/render

That is roughly 7%, and the rendered output is byte-identical. The
interactive TUI was smoke-tested under a pty and behaves the same.

scripts/replace-version.ts had to change too: with splitting the
__PACKAGE_VERSION__ placeholder lands in a chunk rather than in
dist/ccstatusline.js, so patching only the entry would have silently
shipped an unreplaced placeholder. It now patches every emitted script and
fails loudly when it finds none.

Packaging is unaffected: files is already dist/, and bin/main/exports keep
pointing at dist/ccstatusline.js. Verified the built output runs under node
as well as bun.

Assisted-by: claude:claude-opus-5
@sirmalloc
sirmalloc merged commit 35440e4 into sirmalloc:main Sep 18, 2026
pcvelz added a commit to pcvelz/ccstatusline-usage that referenced this pull request Sep 25, 2026
Upstream: TUI kept off the render path (sirmalloc#575), flex mode default full (sirmalloc#590), usage cache fingerprinted by refresh token (sirmalloc#536), CLAUDE_CONFIG_DIR keychain credential first (sirmalloc#573), llms.txt (sirmalloc#527), faster terminal width probing (sirmalloc#501), git/jj symbol slots (sirmalloc#574), model-scoped 0% quota as real zero (sirmalloc#534), custom-command output cache + timeout (sirmalloc#539), usage-percent widgets on a shared module (sirmalloc#545), hideable reset-timer placeholders (sirmalloc#542), git command timeouts (sirmalloc#559, sirmalloc#585)

Hand edits outside conflicts:
- src/widgets/shared/usage-percent-widget.ts: compat fix - pass RenderContext to getUsageProgressBarWidth (fork narrow/medium bar widths) and add fork short labels WS:/WO: that the extracted Sonnet/Opus widgets used to render; point the fable-weekly kind at the fork field weeklyFableUsage / resolveWeeklyFableUsageWindow (upstream's fableUsage / resolveFableUsageWindow do not exist in the fork and crashed the render)
- .fork-keep-deleted: drop llms.txt (points agents at the upstream package and at docs the fork deletes)

Conflict resolutions that deviate from upstream on purpose:
- src/types/Settings.ts: keep fork default flexMode full-minus-40 (upstream sirmalloc#590 switched to full)
- src/utils/terminal.ts: keep fork tmux $TMUX_PANE width probe, ported to execFileSync; upstream's CCSTATUSLINE_WIDTH override in getTerminalWidth replaces the fork copy
- src/ccstatusline.ts: keep getTerminalWidth() without the per-session width cache options (fork invariant); add upstream customCommandCacheTtlSeconds
- src/widgets/WeeklyFableUsage.ts (+ test): keep fork widget (Fable:/F: labels, 0% for accounts without Fable, weeklyFableUsage field) instead of upstream's shared-module FableWeeklyUsage
- src/utils/__tests__/usage-fetch.test.ts: adopt upstream sirmalloc#534 real-zero semantics on the fork field weeklyFableUsage
- docs/test-retirements.md: ledger entries for four tests upstream renamed or replaced (sirmalloc#542, sirmalloc#534) and one duplicate upstream test dropped
- src/utils/__tests__/usage-fetch.test.ts: compat - upstream's model-scoped real-zero test expects the fork field weeklyFableUsage
- src/widgets/__tests__/WeeklyFableUsage.test.ts: compat - set the shared suite's new required expectedWholePercentTime
- src/tui/components/__tests__/ImportPreviewDialog.test.ts: fork deviation - default flexMode is full-minus-40, so the non-default side is full
- src/utils/__tests__/usage-fetch.test.ts: drop upstream's duplicate "missing fable window" test that used the upstream-only fableUsage field
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