Skip to content

text: Avoid quadratic table highlight remapping - #3247

Merged
huacnlee merged 1 commit into
longbridge:mainfrom
lurenjia534:fix/table-highlight-remap
Sep 26, 2026
Merged

huacnlee merged 1 commit into
longbridge:mainfrom
lurenjia534:fix/table-highlight-remap

Conversation

@lurenjia534

Copy link
Copy Markdown
Contributor

Description

A full Markdown update after highlighting search matches repeatedly scans the table from its first row for each highlighted cell. It also recomputes the target row's source endpoint for every cell in that row. Long tables and wide rows therefore cause quadratic reconciliation work on the entity/UI update path.

Collect table row endpoints once in LeafRemap::new and find each cell's row by binary search. Preserve whole-row highlight invalidation, conservative handling of missing source positions, and nested/cross-table boundaries. Append-only remapping skips the row index. Four regression tests cover these cases. The change is confined to one source file and introduces no public API or behavior limits.

Performance

Measured with the production Markdown parser, rendered-text index, public highlight setter and remap. Every x is highlighted, then the final cell of the first data row changes to y. Timings include LeafRemap construction and RangeHighlightFrame::remap.

Table shape (including header) Highlighted cells Before After
32,001 rows × 1 column 32,001 146.280 ms 2.392 ms
64,001 rows × 1 column 64,001 590.392 ms 5.711 ms
100,001 rows × 1 column 100,001 1,467.864 ms 10.104 ms
3 rows × 4,096 columns 12,288 180.165 ms 0.866 ms

Linux x86_64 / Ryzen 9 7950X / Rust 1.98.0; gpui-base uses opt-level=3, with dependencies using the repository's dev profile. Each result is the median of five total-time samples after warm-up. Parsing, search and highlight installation are excluded. These are reconciliation measurements, not GUI frame latency or a full release build.

Screenshot

The screenshots show the actual Rust benchmark output in native terminal windows.

Before After
Table highlight remapping before the fix Table highlight remapping after the fix

Benchmark source, raw results and reproduction instructions are stored separately from the fix so the PR diff contains only the implementation and regression tests.

How to Test

cargo test --locked -p gpui-base --lib
cargo fmt --all -- --check
cargo clippy --locked -p gpui-base --all-targets -- -D warnings
git diff --check

All checks passed; the final library suite reports 1,152 passed, 0 failed. The new tests cover empty cells and missing endpoints, nested tables and table boundaries, long/wide table row invalidation, and the append fast path.

A temporary integration test also passed through public set_text and the background parsed-result commit for a 2,002-highlight table. It verified preserved header highlights/reveal and cleared highlights in the edited and following rows. This instrumentation was removed after validation; its source is included with the linked evidence.

env -u WAYLAND_DISPLAY cargo run --locked -p example-markdown built and displayed on Linux. This was a startup smoke check; full GUI stress testing and macOS/Windows performance testing were not completed.

AI Assistance

AI assisted with the patch, code review, performance reproduction, regression validation and PR preparation.

Checklist

  • I have read the contributing guide and kept this PR focused on one problem.
  • Reviewed the implementation and AI-assisted code against the test evidence.
  • Passed cargo run for related Story tests (Markdown example startup smoke check only).
  • Tested macOS, Windows and Linux performance (Linux reconciliation measurements completed; no platform-specific code changes).

Index table row source endpoints once per full remap and find each cell row by binary search. Preserve whole-row invalidation, missing source positions, nested table boundaries, and the append-only fast path.

@huacnlee huacnlee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the deep performance investigation and optimization, backed by clear benchmarks and regression tests. This kind of careful performance work is very important to GPUI Kit. Approved; Security: PASS for the affected scope.

@huacnlee
huacnlee merged commit fd18012 into longbridge:main Sep 26, 2026
12 checks 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.

2 participants