Repository navigation
terminal: handful of scroll region optimizations (minor) - #13231
Merged
Merged
Conversation
This optimizes scrolling inside a scroll region (DECSTBM). ## The changes 1. **Stop creating scrollback for top-anchored regions on screens that don't retain scrollback.** `index()` routed any full-width region with `top == 0` through `cursorScrollAbove()`, which pushes the scrolled-out row into scrollback. Every scroll paid `PageList.grow()` plus amortized page pruning, which includes a 512 KB `memset` each time a page is recycled. These now use the in-place region scroll instead. CSI S gets the same routing fix. **Result: 1.05x-1.49x on the bottom-anchored region workloads, 1.25x on alt-screen full-screen scrolling.** 2. **Add a specialized `Screen.cursorScrollRegionUp()` for the region scroll hot path.** The previous fast path (`PageList.eraseRowBounded`) paid per-scroll bookkeeping that exceeded the actual row work. The new function is built around the invariant that the cursor sits on the bottom row of a full-width region. **Result: 1.23x-1.24x on the top-anchored region workloads.** ## Benchmarks | workload | region (80 rows) | before | after | change | |---|---|---|---|---| | scrolling (control) | primary screen, no region | 237 ms | 235 ms | 1.0x | | scrolling_bottom_region | alt, rows 1-79 | 243 ms | 231 ms | 1.05x | | scrolling_bottom_small_region | alt, rows 1-40 | 311 ms | 208 ms | 1.49x | | scrolling_top_region | alt, rows 2-80 | 283 ms | 229 ms | 1.23x | | scrolling_top_small_region | alt, rows 40-80 | 258 ms | 208 ms | 1.24x | | alt screen full-screen scrolling | alt, no region | 288 ms | 230 ms | 1.25x | ## LLM Notes Assisted by Fable 5: it diagnosed the vtebench gap, wrote the benchmark harness payloads, profiled, and proposed hot paths. I manually wrote the hot path replacements and had it judge my work.
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.
This optimizes scrolling inside a scroll region (DECSTBM).
We're squeezing blood out of a rock here. There just isn't much improvement to be had given our architecture for this case, but there were a couple things found that result in modest gains.
Vtebench
You can see the modest gains here. Still behind Alacritty (very very close).
The changes
Stop creating scrollback for top-anchored regions on screens that don't retain scrollback.
index()routed any full-width region withtop == 0throughcursorScrollAbove(), which pushes the scrolled-out row into scrollback. Every scroll paidPageList.grow()plus amortized page pruning, which includes a 512 KBmemseteach time a page is recycled. These now use the in-place region scroll instead. CSI S gets the same routing fix. Result: 1.05x-1.49x on the bottom-anchored region workloads, 1.25x on alt-screen full-screen scrolling.Add a specialized
Screen.cursorScrollRegionUp()for the region scroll hot path. The previous fast path (PageList.eraseRowBounded) paid per-scroll bookkeeping that exceeded the actual row work. The new function is built around the invariant that the cursor sits on the bottom row of a full-width region. Result: 1.23x-1.24x on the top-anchored region workloads.Benchmarks
LLM Notes
Assisted by Fable 5: it diagnosed the vtebench gap, wrote the benchmark harness payloads, profiled, and proposed hot paths. I manually wrote the hot path replacements and had it judge my work.