Skip to content

terminal: handful of scroll region optimizations (minor) - #13231

Merged
mitchellh merged 1 commit into
mainfrom
push-wkuprqzmslkv
Jul 7, 2026
Merged

mitchellh merged 1 commit into
mainfrom
push-wkuprqzmslkv

Conversation

@mitchellh

Copy link
Copy Markdown
Contributor

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).

CleanShot 2026-07-06 at 21 18 39@2x

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 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.
@mitchellh
mitchellh requested a review from a team as a code owner July 7, 2026 04:19
@ghostty-bot ghostty-bot Bot added the vt Control sequence related label Jul 7, 2026
@mitchellh mitchellh added this to the 1.4.0 milestone Jul 7, 2026
@mitchellh
mitchellh merged commit 160c3c6 into main Jul 7, 2026
193 checks passed
@mitchellh
mitchellh deleted the push-wkuprqzmslkv branch July 7, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

vt Control sequence related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant