text: Avoid quadratic table highlight remapping - #3247
Merged
Merged
Conversation
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
approved these changes
Sep 26, 2026
huacnlee
left a comment
Member
There was a problem hiding this comment.
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.
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.
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::newand 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
xis highlighted, then the final cell of the first data row changes toy. Timings includeLeafRemapconstruction andRangeHighlightFrame::remap.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.
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 --checkAll 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_textand 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-markdownbuilt 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
cargo runfor related Story tests (Markdown example startup smoke check only).