From 751dd460daa692ee91e81ddacce08ea15366676a Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 23 Jul 2022 13:01:48 -0700 Subject: [PATCH] term: compress rows as they move into scrollback This commit causes lines to be "compressed" (really, just translated to the new clustered line storage variant) as they move into scrollback. The memory savings are significant for large scrollback: `wezterm -n --config scrollback_lines=1000000` `time cat enwiki8.wiki` before: ~9s, Resident: 2.1G after: ~15s, Resident: 620K (!) The performance impact is non-trivial, and I will dig into that next. refs: https://github.com/wez/wezterm/issues/1626 --- term/src/screen.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/term/src/screen.rs b/term/src/screen.rs index 4fd5ee5ac..d75a5697a 100644 --- a/term/src/screen.rs +++ b/term/src/screen.rs @@ -645,6 +645,12 @@ impl Screen { } }; + if scroll_region.start == 0 { + for y in self.phys_range(&(0..num_rows as VisibleRowIndex)) { + self.line_mut(y).compress_for_scrollback(); + } + } + let remove_idx = if scroll_region.start == 0 { 0 } else {