Repository navigation
perf(gpui): speed up 100KB script input and scrolling (105–348× in warm CPU benchmarks) - #3208
Merged
richiemcilroy merged 2 commits intoOct 25, 2026
Conversation
Contributor
|
@kartikkabadi is attempting to deploy a commit to the Cap Software Inc Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Moving the caret or scrolling a long teleprompter script repeatedly scans the full string, rebuilds the interaction layout during flex measurement, and enters glyph loops for offscreen paragraphs. This keeps the warm interaction path short while preserving existing text geometry and editing behavior.
One file, +487 / -72, including five focused regressions. Production code accounts for +192 / -70; tests account for +295 / -2. The cache tracks the complete inherited font, color, text, composition range, font size, line height and active wrap width. Deferred measurement captures the inherited font. Marked text keeps its existing painting path, and paragraph clipping preserves GPUI's fractional row coordinates.
Evidence
Fresh timing comparison against main
ec15b9840344on Apple M1 Pro, macOS 27.0.1, Rust 1.95.0. The exact committed suite was subsequently rebuilt at900dd827b962. Last-checked main100f43a0d359added web/CLI-only changes; its GPUI workspace, Rust crates and build configuration are identical to the tested tip. Both measured text-input sources remain unchanged throughout. The title's rounded range covers the ~100KB key-dispatch/CPU-draw and scroll-redraw cases across ASCII, multilingual and emoji scripts.For the 100KB ASCII fixture with the viewport near the middle:
Ranges of case-level median paired speedups across the full text/position matrix:
These measure elapsed time for warm, synchronous CPU operations in GPUI TestPlatform/NoopTextSystem. Key measurements include binding dispatch and CPU scene preparation; scroll measurements include offset changes and CPU redraw. Native font shaping, OS input latency, GPU presentation, FPS, release-profile performance and export throughput remain unmeasured. The native checks below validate rendering correctness separately.
Immutable evidence snapshot includes all raw samples, fixture sources, compiler profiles, build/test logs, native images, analysis scripts, source hashes and a per-file checksum manifest. The two earlier audit archives are preserved there with their original manifests. Evidence files are outside this PR's code diff.
Benchmark method and reproduction
Raw summary CSV, process metadata, independent analysis, compiler profile, source/patch integrity and reproduction notes.
After the repository's normal native setup, build two disposable checkouts at the recorded baseline and this PR's code commit. The evidence includes exact pure source snapshots and the external audit fixtures. Append the viewport fixture under
cfg(test)to each source, and use:The retained build scripts show the exact commands and native runtime environment used. Adjust their recorded workspace paths for reproduction. Source snapshots and executable hashes identify the audited builds. The native example is built separately with
gpui_platform/test-supportand captures both builds at the same display scale. Executables, app profiles and dependency caches are excluded from the evidence snapshot.All 66 benchmark cases
Times are µs per step. Handler-only rows exclude drawing and are kept separate from the title's key/scroll CPU range.
Correctness, regression tests and final source review
The five repository regressions cover Unicode navigation at every byte offset in explicit fixtures, fractional wrapped-row clipping, width-probe/cache retention, resize/text/style/composition invalidation, and inherited fonts across deferred layout. The seven original exhaustive audit regressions and two independent geometry/composition checks were preserved and rerun outside the code diff.
Unicode verification uses direct old/new evaluation for short inputs and sampled long offsets, with the old forward/reverse iterator boundary oracle for all long offsets. Official Unicode expected chunks provide an independent conformance check. Both production helper bodies exactly match the freshly executed verification sources.
The native fixture uses the real production component, platform fonts and Metal with a fixed test theme. Its current baseline and candidate captures are both 560×320 at the same backing scale. Earlier display scales are retained in separate historical snapshots. Composition/editing/undo/redo checks pass, but these are not real system IME event entry or full signed-in app acceptance.
The other 24 existing ignored tests are opt-in audio/device/GPU/fixture benchmarks and real-app recording/upload integrations. They remain unexecuted; the logs list every ignored test and any recorded reason. No check was weakened or production failure waived.
Committed test output, extended test output, cache diagnostic, validation record, native captures, Unicode verification, Clippy output, formatting baseline comparison and final source review.
The final review traced settings/search, renaming, editor fields, screenshot/annotation inputs and teleprompter editing/scrolling. It checked cache ownership and invalidation, Unicode context, measurement geometry, clipping/decorations, the deferred font lifetime and shared public contracts. No unresolved correctness finding remained.
Latest main and duplicate PR check
Rechecked upstream main and the changed-file lists of all 154 open PRs, plus 100 recently merged PRs and historical text-input/grapheme/teleprompter searches. No published duplicate found in that audit.
The only open PR touching this file is #2587; its patch changes theme styling and removes
selection_tint. It does not implement grapheme cursor navigation, measurement retention or paragraph culling. Recently merged #3125 only adds the focus accessor in this file, which this patch preserves. #2773 handles platform editing shortcuts, #2524/#2739 concern renderer text-overlay caches, and #3104 concerns platform frame scheduling.Compared with the original audit base, current main's only change in this file is
is_focused. It is preserved. The exact suite was rebuilt and rerun after the unrelated Windows-picker change at900dd827b962. The PR branch starts at last-checked main100f43a0d359; its later web/CLI-only commits leave all GPUI workspace, Rust crate and build-configuration trees identical to that tested tip. Both measured text-input sources remain byte-identical. Source-tree identity record, duplicate audit record.Merge danger
Door: two-way. Reverting this one-file change restores the previous implementation. There are no dependency, persistence, migration, recording or export format changes.
Blast radius: shared text fields. Native Windows/Linux execution, system IME event entry and full signed-in app acceptance were not performed locally. Cold shaping, text edits, style changes and resizing can still scale with document length. Some Unicode boundaries require scanning surrounding context, and marked composition deliberately bypasses paragraph culling. This is a scoped improvement to warmed input and CPU redraw work.


Confidence Score: 5/5
The reviewed changes appear safe to merge; no actionable issue was found.Summary
Speeds up shared GPUI text fields by finding nearby grapheme boundaries, keeping the active layout during width measurements, and skipping fully clipped paragraphs.
Reviews (1) · Last reviewed commit: "perf(gpui): reuse text layouts during lo..." · Reviewed by Greptile