Throttle scrollbar updates to improve performance #5064

Closed
opened 2026-01-31 00:04:07 +00:00 by claunia · 7 comments
Owner

Originally created by @beviu on GitHub (Nov 18, 2019).

PR #3531 added this code to throttle scrollbar updates to reduce CPU usage:

ee087cfd29/src/cascadia/TerminalControl/TermControl.cpp (L1419-L1432)

But the code skips the last scroll update. If we have 4 updates very quickly, then:

  • 1st will set the _lastScrollTime and update the scrollbar
  • 2nd will return because the time difference is too small but will reset _lastScrollTime for the next one (BTW why reset? we could skip the next one too)
  • 3rd will set the _lastScrollTime and update the scrollbar
  • 4th will return because the time difference is too small but will reset _lastScrollTime for the next one

So we missed the last update (the 4th) and now the scrollbar has invalid value.

@skyline75489

Originally created by @beviu on GitHub (Nov 18, 2019). PR #3531 added this code to throttle scrollbar updates to reduce CPU usage: https://github.com/microsoft/terminal/blob/ee087cfd2929c1d592e8d169d609da97363d74e7/src/cascadia/TerminalControl/TermControl.cpp#L1419-L1432 But the code skips the last scroll update. If we have 4 updates very quickly, then: - 1st will set the `_lastScrollTime` and update the scrollbar - 2nd will return because the time difference is too small but will reset `_lastScrollTime` for the next one (BTW why reset? we could skip the next one too) - 3rd will set the `_lastScrollTime` and update the scrollbar - 4th will return because the time difference is too small but will reset `_lastScrollTime` for the next one So we missed the last update (the 4th) and now the scrollbar has invalid value. @skyline75489
Author
Owner

@DHowett-MSFT commented on GitHub (Nov 18, 2019):

@greg904 you want to take a crack at this? 😄

@DHowett-MSFT commented on GitHub (Nov 18, 2019): @greg904 you want to take a crack at this? :smile:
Author
Owner

@skyline75489 commented on GitHub (Nov 19, 2019):

Thanks @greg904 . Is this a theoritical bug or a pratical one that you experienced yourself ? I can't reproduce this kind of inconsistency. Guess most of the time there'll be a fifth update that corrects the state.

And about resetting the value to nullopt. I originally put it there to prevent some kind of bad situation. But you're right. It can be safely removed now, I think.

@skyline75489 commented on GitHub (Nov 19, 2019): Thanks @greg904 . Is this a theoritical bug or a pratical one that you experienced yourself ? I can't reproduce this kind of inconsistency. Guess most of the time there'll be a fifth update that corrects the state. And about resetting the value to `nullopt`. I originally put it there to prevent some kind of bad situation. But you're right. It can be safely removed now, I think.
Author
Owner

@beviu commented on GitHub (Nov 19, 2019):

Here is a repro:

  1. open terminal with powershell
  2. type 1..100
  3. grab scrollbar and scroll a little bit up and then back to the bottom in one go
  4. notice that the viewport isn't exactly at the bottom (it is one line above so you don't see the prompt) because the scrollbar's max value hasn't changed so it still thinks that the bottom is the old bottom

@DHowett-MSFT I will try to do a PR but I was waiting for my other PR #3344 to be merged. Or maybe I can also add a fix for this in it?

@beviu commented on GitHub (Nov 19, 2019): Here is a repro: 1. open terminal with powershell 2. type `1..100` 3. grab scrollbar and scroll a little bit up and then back to the bottom in one go 4. notice that the viewport isn't exactly at the bottom (it is one line above so you don't see the prompt) because the scrollbar's max value hasn't changed so it still thinks that the bottom is the old bottom @DHowett-MSFT I will try to do a PR but I was waiting for my other PR #3344 to be merged. Or maybe I can also add a fix for this in it?
Author
Owner

@DHowett-MSFT commented on GitHub (Nov 20, 2019):

Let's make sure that 3344 gets reviewed. Really sorry about the delay there. If you want to stage another PR that builds on top of that one, I'm sure that'd be fine 😄

@DHowett-MSFT commented on GitHub (Nov 20, 2019): Let's make sure that 3344 gets reviewed. Really sorry about the delay there. If you want to stage another PR that builds on top of that one, I'm sure that'd be fine :smile:
Author
Owner

@zadjii-msft commented on GitHub (Nov 21, 2019):

With #3660 reverting this for v0.7, this is now the "Throttle scrollbar updates to improve perf" issue

@zadjii-msft commented on GitHub (Nov 21, 2019): With #3660 reverting this for v0.7, this is now the "Throttle scrollbar updates to improve perf" issue
Author
Owner

@ghost commented on GitHub (Jun 18, 2020):

:tada:This issue was addressed in #4608, which has now been successfully released as Windows Terminal Preview v1.1.1671.0.🎉

Handy links:

@ghost commented on GitHub (Jun 18, 2020): :tada:This issue was addressed in #4608, which has now been successfully released as `Windows Terminal Preview v1.1.1671.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v1.1.1671.0) * [Store Download](https://www.microsoft.com/store/apps/9n0dx20hk701?cid=storebadge&ocid=badge)
Author
Owner

@ghost commented on GitHub (Jun 30, 2020):

:tada:This issue was addressed in #4608, which has now been successfully released as Windows Terminal v1.0.1811.0.🎉

Handy links:

@ghost commented on GitHub (Jun 30, 2020): :tada:This issue was addressed in #4608, which has now been successfully released as `Windows Terminal v1.0.1811.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v1.0.1811.0) * [Store Download](https://www.microsoft.com/store/apps/9n8g5rfz9xk3?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#5064