Skip to content

gpui: Optimize text shaping in debug builds - #3012

Open
huacnlee wants to merge 1 commit into
mainfrom
agent/T-10965-gpui-input-timeout
Open

huacnlee wants to merge 1 commit into
mainfrom
agent/T-10965-gpui-input-timeout

Conversation

@huacnlee

Copy link
Copy Markdown
Member

Summary

The GPUI gallery job's typing a long line completes in one host step test (crates/nsh-testing/tests/testing/input-target/gpui/Input.test.tsx) fails on CI with the host did not take the step in 30 s (e.g. #3005, #2997, #2952); a re-run fails the same way.

This builds the text-shaping crates (cosmic-text, harfrust, read-fonts, font-types) at opt-level = 3 in the GPUI workspace's dev profile, as taffy, tiny-skia and syntect already are. No code, test text, timeout or acknowledgment behaviour changes.

Why

Profiled the debug GPUI host under Xvfb (the CI setup):

  • Each typed character's own work is constant: the edit about 1 µs, the engine's event + commit about 75 µs, batch apply and IME queries negligible.
  • The time goes to the main thread being busy when the engine's acknowledgment arrives, and that grows with the text length (0.07 ms per char at 1k characters, up to 1 ms at 6–7k).
  • Stack samples of that main-thread time show a window draw in InputState::draw → text_input::layout::shape_paragraph → GPUI shape_line_uncached → cosmic-text → harfrust. The Input caches its layout, but every edit changes the text, so each character reshapes the whole line once: O(n) per character, O(n²) for the step. The test's text is a single 10,240-character word, so no word-level caching would help.
  • In a debug build harfrust is unoptimized, so the hosted runner goes over 30 s.

Moving the per-character round trips onto the main thread made no difference under contention, so that was not the bottleneck and is not part of this PR.

Measurements (local, debug host, Xvfb, same test)

before after
idle machine 6.4–6.7 s 3.9–4.4 s
2 cores shared with 2 busy loops 19.9–21.2 s 11.9 s

Cost: the four crates take a little longer to build the first time in debug (the host rebuilt in 43 s here).

Testing

  • nsh test crates/nsh-testing/tests/testing/input-target/gpui/Input.test.tsx --target gpui (all 3, including the unacknowledged-edit abort): pass
  • .../gpui/Editor.test.tsx and App.test.tsx --filter 'shared prefix' in GPUI windows: pass
  • The hosted runner's result is in this PR's GPUI gallery job; not yet observed.

Follow-up worth considering separately: reshaping only the edited part of a long single-line Input (real typing pays the same per-edit O(n) cost in release, just faster).

🤖 Generated with Claude Code

🤖 Noop (rust-maintainer) · AI agent acting for @huacnlee

An Input shapes its whole line again after each edit. In the debug host
that CI's GPUI gallery job runs, unoptimized harfrust and cosmic-text
made typing 10,240 characters in one step miss the host's 30 s step
timeout on the hosted runner. Build the shaping crates at opt-level 3 in
the dev profile, as taffy, tiny-skia and syntect already are.

Agent: rust-maintainer
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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