1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-23 23:21:08 +03:00

gui: cache get_lines_with_hyperlinks_applied

If the pane is unchanged and we're at the same viewport, cache
the values from the last call.
This commit is contained in:
Wez Furlong 2022-08-23 17:39:56 -07:00
parent e05b3581b8
commit 0141d340f3
2 changed files with 53 additions and 14 deletions

View File

@ -49,13 +49,13 @@ use smol::channel::Sender;
use smol::Timer; use smol::Timer;
use std::cell::{RefCell, RefMut}; use std::cell::{RefCell, RefMut};
use std::collections::HashMap; use std::collections::HashMap;
use std::ops::Add; use std::ops::{Add, Range};
use std::rc::Rc; use std::rc::Rc;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use termwiz::hyperlink::Hyperlink; use termwiz::hyperlink::Hyperlink;
use termwiz::surface::SequenceNo; use termwiz::surface::{Line, SequenceNo};
use wezterm_dynamic::Value; use wezterm_dynamic::Value;
use wezterm_font::FontConfiguration; use wezterm_font::FontConfiguration;
use wezterm_gui_subcommands::GuiPosition; use wezterm_gui_subcommands::GuiPosition;
@ -191,6 +191,19 @@ pub struct PaneState {
bell_start: Option<Instant>, bell_start: Option<Instant>,
pub mouse_terminal_coords: Option<(ClickPosition, StableRowIndex)>, pub mouse_terminal_coords: Option<(ClickPosition, StableRowIndex)>,
/// Cache to avoid calling pane.get_lines_with_hyperlinks_applied
/// if the pane hasn't changed since the last render
pub logical_line_cache: Option<CachedLogicalLines>,
}
pub struct CachedLogicalLines {
// Key fields
pub seqno: SequenceNo,
pub stable_range: Range<StableRowIndex>,
// Value fields
pub top: StableRowIndex,
pub lines: Rc<Vec<Line>>,
} }
/// Data used when synchronously formatting pane and window titles /// Data used when synchronously formatting pane and window titles

View File

@ -10,7 +10,8 @@ use crate::renderstate::BorrowedLayers;
use crate::shapecache::*; use crate::shapecache::*;
use crate::tabbar::{TabBarItem, TabEntry}; use crate::tabbar::{TabBarItem, TabEntry};
use crate::termwindow::{ use crate::termwindow::{
BorrowedShapeCacheKey, RenderState, ScrollHit, ShapedInfo, TermWindowNotif, UIItem, UIItemType, BorrowedShapeCacheKey, CachedLogicalLines, RenderState, ScrollHit, ShapedInfo, TermWindowNotif,
UIItem, UIItemType,
}; };
use crate::uniforms::UniformBuilder; use crate::uniforms::UniformBuilder;
use crate::utilsprites::RenderMetrics; use crate::utilsprites::RenderMetrics;
@ -1363,17 +1364,42 @@ impl super::TermWindow {
None => dims.physical_top..dims.physical_top + dims.viewport_rows as StableRowIndex, None => dims.physical_top..dims.physical_top + dims.viewport_rows as StableRowIndex,
}; };
let start = Instant::now(); let seqno = pos.pane.get_current_seqno();
let (top, vp_lines) = pos let mut state = self.pane_state(pos.pane.pane_id());
.pane
.get_lines_with_hyperlinks_applied(stable_range, &self.config.hyperlink_rules); (stable_top, lines) = state
metrics::histogram!("get_lines_with_hyperlinks_applied.latency", start.elapsed()); .logical_line_cache
log::trace!( .as_ref()
"get_lines_with_hyperlinks_applied took {:?}", .and_then(|cached| {
start.elapsed() if cached.seqno == seqno && cached.stable_range == stable_range {
); Some((cached.top, Rc::clone(&cached.lines)))
stable_top = top; } else {
lines = vp_lines; None
}
})
.unwrap_or_else(|| {
let start = Instant::now();
let (top, vp_lines) = pos.pane.get_lines_with_hyperlinks_applied(
stable_range.clone(),
&self.config.hyperlink_rules,
);
metrics::histogram!(
"get_lines_with_hyperlinks_applied.latency",
start.elapsed()
);
log::trace!(
"get_lines_with_hyperlinks_applied took {:?}",
start.elapsed()
);
let lines = Rc::new(vp_lines);
state.logical_line_cache = Some(CachedLogicalLines {
seqno,
stable_range,
top,
lines: Rc::clone(&lines),
});
(top, lines)
});
} }
let gl_state = self.render_state.as_ref().unwrap(); let gl_state = self.render_state.as_ref().unwrap();