Skip to content

input: Reuse measured wraps during live resize - #3691

Open
T-miracle wants to merge 3 commits into
longbridge:mainfrom
T-miracle:fix-live-wrap-resize
Open

T-miracle wants to merge 3 commits into
longbridge:mainfrom
T-miracle:fix-live-wrap-resize

Conversation

@T-miracle

@T-miracle T-miracle commented Oct 25, 2026 •

Copy link
Copy Markdown

Description

Dragging a divider beside a soft-wrapped editor can lag because each width change measures the document again.

Reuse valid line breaks and exact measured text widths. Lines rewrap immediately when their breaks change, so wrapping stays live throughout the drag.

width changes → reuse valid wraps → rewrap only where needed

Integrated main (7b14e03), including #3622's Tab measurements. Changing the tab size clears cached measurements and recalculates wrapping.

Four Base input files; no public API or dependency changes. The width cache holds up to 32,768 entries and 4 MiB of text, plus bookkeeping overhead.

Screenshot

Actual recording: before on top, after on bottom

Real Windows native editor recordings, captured separately with the same 1,500-line drag test. Original speed, 25 fps; only startup waiting, framing and English labels were edited. This recording predates the main integration.

How to Test

Open a soft-wrapped editor with long text and tabs, then drag its divider back and forth. Wrapping should update during the drag; changing font or tab size must recalculate it.

Windows validation on the updated branch:

  • 2,750 unit/integration tests and 2 doc tests passed across Base, Component, Kit and Story.
  • Native-font regression checks compare cached wrapping with the original algorithm using Arial/Consolas, two sizes, both indentation modes and Tab sizes 0/2/4/8. Changing Tab size on a warm cache is covered separately.
  • Formatting and Clippy (--all-targets --deny warnings) passed.
  • Windows Story: Editor with 1,500 lines, native window narrowing/widening and a font-size change; Textarea with long Unicode text. Accessible values stayed unchanged and screenshots confirmed reflow. Window sizing used the OS keyboard controls.
  • Cross-platform CI results are available in the Checks tab.
cargo test -p gpui-base -p gpui-component -p gpui-kit -p gpui-component-story \
  --features gpui-component-story/test-support --locked

Earlier CPU resize-and-draw measurements on the fixed 0.8.0 baseline and original patch, Windows Release/native fonts/1,500 lines:

Before After
Horizontal p50 178.32 ms 0.39 ms
Horizontal p95 180.91 ms 0.41 ms

These used 32 measured samples after four warm-up samples, without recording. They are historical CPU timings; current-main and macOS/Linux performance numbers have not been measured.

Merge Danger

Reversible internal optimization. Wrapping affects caret, selection and inline layout; large wrap changes can still cause slow frames.

Implementation, tests, description and recording preparation were AI-assisted.

Checklist

  • Read CONTRIBUTING and followed the applicable guidelines.
  • Contributor review of AI-generated code.
  • Passed the related Story checks.
  • Tested performance on macOS, Windows and Linux.

@T-miracle
T-miracle marked this pull request as ready for review October 26, 2026 01:04
@huacnlee

Copy link
Copy Markdown
Member

I've prepared a fix for the oversized-word measurement regression in 54a6eee. It bounds word-boundary probes and falls back to local grapheme probing for long words. All 20 related tests, Clippy, formatting and diff checks passed.

Please cherry-pick it onto this PR:

git fetch https://github.com/longbridge/gpui-kit.git fix/pr-3691-local-wrap-measurements
git cherry-pick 54a6eeeb32e25857e1b6a8c6c91c2802bd90dc5c

For future PRs, please enable Allow edits from maintainers so we can push follow-up fixes directly to your branch. This PR currently has that option disabled, and GitHub rejected the push with permission denied.

Limit word-boundary probes to a local grapheme window. Fall back to the original exponential grapheme search when a candidate lies beyond it, preserving legal word boundaries and conservative width reuse intervals.

Add a regression that compares original wrapping and bounds shaped bytes for 8K/16K words, narrow and wide viewports, leading words and both indentation modes.

AI-assisted implementation and regression validation.

(cherry picked from commit 54a6eee)
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