From 1b989b011dd86b7d4e1dffbd9196a92c074b0873 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 19 Feb 2018 08:14:03 -0800 Subject: [PATCH] improve scroll_up perf We were marking the entire scrollback history as dirty on each line scroll. This was from the early days and isn't needed any more. This brings the runtime of: ``` $ find /usr > /tmp/usr-files.txt $ time cat /tmp/usr-files.txt ``` down from ~2.5s to ~1.2s. Also avoid a redundant line_mut() call in set_cell(). --- term/src/screen.rs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/term/src/screen.rs b/term/src/screen.rs index 7a07e37ed..adad51393 100644 --- a/term/src/screen.rs +++ b/term/src/screen.rs @@ -105,18 +105,19 @@ impl Screen { attr ); + let line = self.line_mut(line_idx); + if attr.hyperlink.is_some() { - self.line_mut(line_idx).set_has_hyperlink(true); + line.set_has_hyperlink(true); } - let cells = &mut self.line_mut(line_idx).cells; - let width = cells.len(); + let width = line.cells.len(); // if the line isn't wide enough, pad it out with the default attributes if x >= width { - cells.resize(x + 1, Cell::default()); + line.cells.resize(x + 1, Cell::default()); } - cells[x] = Cell::from_char(c, attr); - &cells[x] + line.cells[x] = Cell::from_char(c, attr); + &line.cells[x] } pub fn clear_line(&mut self, y: VisibleRowIndex, cols: std::ops::Range) { @@ -179,7 +180,7 @@ impl Screen { pub fn scroll_up(&mut self, scroll_region: &Range, num_rows: usize) { debug!("scroll_up {:?} {}", scroll_region, num_rows); let phys_scroll = self.phys_range(&scroll_region); - assert!(num_rows <= phys_scroll.end - phys_scroll.start); + debug_assert!(num_rows <= phys_scroll.end - phys_scroll.start); // Invalidate the lines that will move before they move so that // the indices of the lines are stable (we may remove lines below) @@ -207,14 +208,6 @@ impl Screen { self.lines.remove(phys_scroll.start); } - if scroll_region.start == 0 { - // All of the lines above the top are now effectively dirty because - // they were moved into scrollback by the scroll operation. - for y in 0..phys_scroll.start { - self.line_mut(y).set_dirty(); - } - } - if scroll_region.end as usize == self.physical_rows { // It's cheaper to push() than it is insert() at the end for _ in 0..num_rows {