# terminal: Improve scroll performance \(\#44714\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/73b37e9774399780fb49901a4a2d0b025db4a2a8)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 73b37e9774399780fb49901a4a2d0b025db4a2a8

Requested commit: 73b37e9774399780fb49901a4a2d0b025db4a2a8

Commit: 73b37e9774399780fb49901a4a2d0b025db4a2a8

Tree: 526d154684b0eb7073cd08ac5cc15111552ce720

Author: Dave Waggoner

Committer: GitHub

## Message

```
terminal: Improve scroll performance (#44714)

Related to: 
- #44510 
- #44407 

Previously we were searching for hyperlinks on every scroll, even if Cmd
was not held. With this PR,
- We only search for hyperlinks on scroll if Cmd is held
- We now clear `last_hovered_word` in all cases where Cmd is not held
- Renamed `word_from_position` -> `schedule_find_hyperlink`
- Simplified logic in `schedule_find_hyperlink`

Performance measurements

The test scrolls up and down 20,000x in a loop. However, since this PR
is just removing a code path that was very dependent on the length of
the line in terminal, it's not super meaningful as a comparison. The
test uses a line length of "long line ".repeat(1000), and in main the
performance is directly proportional to the line length, so for
benchmarking it in main it only scrolls up and down 20x. I think all
that is really useful to say is that currently scrolling is slow, and
proportional to the line length, and with this PR it is buttery-smooth
and unaffected by line length. I've included a few data points below
anyway. At least the test can help catch future regressions.
 
| Branch | Command | Scrolls | Iter/sec | Mean [ms] | SD [ms] |
Iterations | Importance (weight) |
|:---|:---|---:|---:|---:|---:|---:|---:|
| main | tests::perf::scroll_long_line_benchmark | 40 | 16.85 | 712.00 |
2.80 | 12 | average (50) |
| this PR | tests::perf::scroll_long_line_benchmark | 40 | 116.22 |
413.60 | 0.50 | 48 | average (50) |
| this PR | tests::perf::scroll_long_line_benchmark | 40,000 | 9.19 |
1306.40 | 7.00 | 12 | average (50) |
| only overhead | tests::perf::scroll_long_line_benchmark | 0 | 114.29 |
420.90 | 2.00 | 48 | average (50) |


Release Notes:

- terminal: Improved scroll performance
```

## Parents

- [1104ac7f7c61a33d5a32161c19cecd5aefbad5e9](https://git.cafe/gitcafe/zed/commit/1104ac7f7c61a33d5a32161c19cecd5aefbad5e9?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/73b37e9774399780fb49901a4a2d0b025db4a2a8?format=markdown)
