Repository navigation
rioterm: compress the scrollback of terminals no one is using (scrollback-compression) - #2134
Open
raphamorim wants to merge 18 commits into
Open
raphamorim wants to merge 18 commits into
raphamorim wants to merge 18 commits into
Conversation
…mpression) The thread reading the PTY compresses the history 250 ms after the last output (5 s at most while output never pauses), four blocks a step, a millisecond apart, taking the terminal only when it's free. A resize starts it too (a column change decompresses the history to reflow it). Crosswords::set_scrollback_compression turns it on, off by default for embedders; rioterm sets it from the new scrollback-compression option, on by default, and again on reload.
… time; scrolling back schedules a pass - No more deadline 5 s after output started: under output that never pauses, a step ran on every read, compressing the oldest rows, the ones about to be dropped, on the thread that parses. - A step compresses 256K cells (a block at least), not 4 blocks, so a wide terminal holds the lock as briefly as a narrow one. - The terminal tells the reader when the viewport moves over the history (Msg::Compress, once per pass): what showing it decoded is dropped once things are quiet. - A reloaded scrollback-compression reaches tabs and splits opened afterwards too.
… a block per step; a step every 100 ms while rows keep coming - The idle wait starts over when rows arrive in the history (either screen's size or evicted count changes), not on any output: a spinner or a redraw on screen, or a program on the alt screen, kept pushing it back, so a session with one never had its history compressed. - A step compresses one block and goes on where the last stopped (about 0.1 ms at 120 columns, against about 1 ms), so a keystroke's echo waits as little behind one. - While rows keep arriving (a long build log), a block is compressed every 100 ms all the same, a fraction of a percent of the parsing thread, instead of none until the output pauses.
…pression # Conflicts: # CHANGELOG.md
… needed The loop read it on every wakeup to see if a step was due, compression on or not; it does only while a pass is scheduled. After a burst it's read only when rows arrived in the history (the timer is armed).
…t is kept - A pass waited 100 ms from the first change whatever came after: the backstop was shorter than the quiet interval. It is now 1 s, so output that pauses gets its 250 ms. - Only scrolling asked for the decoded copies to go. A search or a snapshot over the history left them until rows next arrived; now a block's first decode asks (once until a pass starts), and that pass looks over the whole ring. - Turning compression on asks for a pass for what came in while off.
…pression # Conflicts: # rio-vt/src/crosswords/grid/compress.rs # rio-vt/src/crosswords/grid/mod.rs # rio-vt/src/crosswords/grid/storage.rs
…ut a pass off until they stop - The backstop's pass compressed one block a second: each step after the first was put off again by the next output. It now compresses COMPRESS_FLOWING_BLOCKS (16) a step at a time before output can. - Scrolling over the history restarts the quiet wait each time (not only the first), so a pass doesn't drop copies the user is still scrolling through. Reads don't count toward the backstop. - A block's first decode signals after decoding, not inside the cell's initialisation.
…pression # Conflicts: # rio-vt/src/crosswords/grid/compress.rs
…om the PTY reader The PTY reader no longer schedules compression: its timer, backstop, Msg::Compress and the read signal are gone, and rio-vt is back to the compress_history API (plus TerminalLock::try_lock and a CompressScrollback event for the application's timer). rioterm looks at every terminal once a second. One with no input written to it and its viewport not moved for 5 s has its history compressed a millisecond at a time, only when no one holds its lock: at full speed once rows stop arriving, at 16 blocks a second while they keep coming (a background build, tail -f), so a flood isn't slowed and rows about to leave the history aren't compressed for nothing. Typing or scrolling in it puts it off for another 5 s.
… its budget, and output under a scrolled-back view isn't use - What a pass leaves is keyed by the history's rows, the width (a column resize decompresses it all) and the viewport's moves, counted by rio-vt's scroll_display (Crosswords::viewport_moves): a scroll up and back between two looks is seen, and output that moves the offset to keep a scrolled-back view still isn't taken for someone scrolling. - A look while rows keep coming stops at the 1 ms budget too, and a terminal starts nothing once the budget is spent. - A busy terminal waits for the next look a second later instead of asking for one every 10 ms. - The timers' ids are out of window and route ids' range (unschedule_window drops timers by id).
… (input, keys, mouse, wheel on its window), not by viewport moves
This branch has not been deployed
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.
Builds on #2131 (compressed scrollback in rio-vt). Rio now compresses the scrollback of terminals no one is using.
Config
Turning it off at runtime stops compression; what is already compressed stays that way until it is written to. Turning it on picks up at the next look.
scrollback-history-limitstill counts lines either way.When it runs. rioterm decides, not the PTY reader: it knows when someone is using a terminal.
Messenger::send_write), or when keys, the mouse, the wheel, IME or touch reach its window while it's on screen (Screen::mark_in_use, for every pane of the tab shown, since the wheel scrolls the pane under the pointer). Both setMessenger::last_use. Scrolling back is wheel or keys, so it counts. Output doesn't, even under a scrolled-back view, where it moves the viewport's offset to keep the view in place.IDLE_COMPRESS_AFTER) has its history compressed. Work stops after about 1 ms each look, across all terminals; once that's spent, the rest start nothing. If there's more, the next look comes 10 ms later.TerminalLock::try_lock, which doesn't ask the reader to make way). If the PTY reader or a frame has it, the next look a second later tries again.tail -f, an agent in a background tab. While rows keep arriving between looks, a look compresses at most 16 blocks (4096 lines). That costs about 2 ms of the terminal's lock a second, so a flood isn't slowed, and rows about to leave the history aren't compressed for nothing. Once rows stop arriving it runs at full speed.Searches through the history and snapshots leave nothing decoded behind (#2131), so they need no pass afterwards.
PTY path. The PTY reader does no compression work. rio-vt here is #2131's plus two additions:
TerminalLock::try_lockand aRioEvent::CompressScrollbackfor the application's timer.Stress test: rio itself. A release build with
scrollback-history-limit = 100000rancaton a 38 MB log of 500k colored build-output lines. Nothing was typed into the window. The process's footprint (macOSfootprint) was sampled every 0.5 s.cat(about 1 s)scrollback-compression = falsecat, then settled at 99 MB. I didn't find the cause, and it didn't happen in the other runs.With #2131's slabs, the history's rows live in OS mappings, unmapped once compressed, so the footprint follows. 8 terminals of 10k lines go from 82 MB to 14–20 MB, also after a full read or a column resize.
Tests
an_idle_terminal_has_its_scrollback_compressed:scrolling_puts_compression_off_and_flowing_output_gets_a_few_blocks:what_changes_the_history_without_rows_is_compressed_again: a column resize, and a scroll up and back between two looks (it fails if the done-key leaves out the last use).output_under_a_scrolled_back_view_isnt_someone_using_it: output moving a scrolled-back view's offset leaveslast_usealone.test_scrollback_compression: the option's default andfalse.