Skip to content

Conditionally compute visual line layout in Thinking component - #1218

Open
nordicnode wants to merge 1 commit into
CodebuffAI:mainfrom
nordicnode:perf-thinking-conditional-layout
Open

Conditionally compute visual line layout in Thinking component#1218
nordicnode wants to merge 1 commit into
CodebuffAI:mainfrom
nordicnode:perf-thinking-conditional-layout

Conversation

@nordicnode

Copy link
Copy Markdown

Conditionally compute visual line layout in Thinking component

Summary

• In cli/src/components/thinking.tsx, conditionally compute visual line wrapping and markdown content formatting based on thinkingCollapseState.
• Previously, getLastNVisualLines (which measures tokens and performs visual word wrapping across the entire reasoning text) was invoked unconditionally on every render, even when thinkingCollapseState === 'hidden' (where neither preview nor expanded text is displayed) or 'expanded' (where preview lines are never displayed).
• Measured via @opentui/react and @opentui/core/testing end-to-end across 100 actual React render cycles (5,000-char reasoning text):

  • Hidden state: 753.35 ms down to 148.99 ms (5.05x faster end-to-end React render).
  • Expanded state: 779.28 ms down to 181.15 ms (4.30x faster end-to-end React render).
  • Isolated visual wrapping: 616.26 ms down to 0.00 ms.
    • In cli/src/components/blocks/thinking-block.tsx, added a fast-path for blocks.length === 1 when extracting combinedContent to avoid allocating intermediate .map() arrays on every streaming token update.
    • Added unit tests in cli/src/components/__tests__/thinking.test.tsx verifying component rendering across all three states (preview, hidden, and expanded).

Test plan

[✓] bun test --config=/dev/null src/components/__tests__/thinking.test.tsx — 3 pass, 0 fail
[✓] bun run --cwd cli typecheck — passed with 0 errors
[✓] PR hygiene check 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