1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-15 10:07:39 -05:00

Apply UPDATE_DELAY in arrears, not in advance.

The original aim of the rate limit was to avoid having too many
updates per second. I implemented this by a deferment mechanism: when
any change occurs that makes the terminal want an update, it instead
sets a timer to go off after UPDATE_DELAY (1/50 second), and does the
update at the end of that interval.

Now it's done the other way round: if there has not been an update
within the last UPDATE_DELAY, then we can simply do an update _right
now_, in immediate response to whatever triggered it. And _then_ we
set a timer to track a cooldown period, within which any further
requests for updates will be deferred until the end of the cooldown.

This mechanism should still rate-limit updates, but now the latency in
normal interactive use should be lowered, because terminal updates in
response to keystrokes (which typically arrive separated by more than
UPDATE_DELAY) can now each be enacted as soon as possible after the
triggering keystroke.

This also reverses (in the common case) the slowdown of non-textual
window modifications introduced by the previous commit, in which lots
of them were brought under the umbrella of term_update and therefore
became subject to UPDATE_DELAY. Now they'll only be delayed in
conditions of high traffic, and not in interactive use.
This commit is contained in:
Simon Tatham
2021-02-07 19:59:21 +00:00
parent d74308e90e
commit 334688db81
2 changed files with 35 additions and 11 deletions

View File

@ -259,11 +259,17 @@ struct terminal_tag {
bool in_term_out;
/*
* We schedule a window update shortly after receiving terminal
* data. This tracks whether one is currently pending.
* We don't permit window updates too close together, to avoid CPU
* churn pointlessly redrawing the window faster than the user can
* read. So after an update, we set window_update_cooldown = true
* and schedule a timer to reset it to false. In between those
* times, window updates are not performed, and instead we set
* window_update_pending = true, which will remind us to perform
* the deferred redraw when the cooldown period ends and
* window_update_cooldown is reset to false.
*/
bool window_update_pending;
long next_update;
bool window_update_pending, window_update_cooldown;
long window_update_cooldown_end;
/*
* Track pending blinks and tblinks.