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:
parent
e05b3581b8
commit
0141d340f3
@ -49,13 +49,13 @@ use smol::channel::Sender;
|
||||
use smol::Timer;
|
||||
use std::cell::{RefCell, RefMut};
|
||||
use std::collections::HashMap;
|
||||
use std::ops::Add;
|
||||
use std::ops::{Add, Range};
|
||||
use std::rc::Rc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::{Duration, Instant};
|
||||
use termwiz::hyperlink::Hyperlink;
|
||||
use termwiz::surface::SequenceNo;
|
||||
use termwiz::surface::{Line, SequenceNo};
|
||||
use wezterm_dynamic::Value;
|
||||
use wezterm_font::FontConfiguration;
|
||||
use wezterm_gui_subcommands::GuiPosition;
|
||||
@ -191,6 +191,19 @@ pub struct PaneState {
|
||||
|
||||
bell_start: Option<Instant>,
|
||||
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
|
||||
|
@ -10,7 +10,8 @@ use crate::renderstate::BorrowedLayers;
|
||||
use crate::shapecache::*;
|
||||
use crate::tabbar::{TabBarItem, TabEntry};
|
||||
use crate::termwindow::{
|
||||
BorrowedShapeCacheKey, RenderState, ScrollHit, ShapedInfo, TermWindowNotif, UIItem, UIItemType,
|
||||
BorrowedShapeCacheKey, CachedLogicalLines, RenderState, ScrollHit, ShapedInfo, TermWindowNotif,
|
||||
UIItem, UIItemType,
|
||||
};
|
||||
use crate::uniforms::UniformBuilder;
|
||||
use crate::utilsprites::RenderMetrics;
|
||||
@ -1363,17 +1364,42 @@ impl super::TermWindow {
|
||||
None => dims.physical_top..dims.physical_top + dims.viewport_rows as StableRowIndex,
|
||||
};
|
||||
|
||||
let start = Instant::now();
|
||||
let (top, vp_lines) = pos
|
||||
.pane
|
||||
.get_lines_with_hyperlinks_applied(stable_range, &self.config.hyperlink_rules);
|
||||
metrics::histogram!("get_lines_with_hyperlinks_applied.latency", start.elapsed());
|
||||
log::trace!(
|
||||
"get_lines_with_hyperlinks_applied took {:?}",
|
||||
start.elapsed()
|
||||
);
|
||||
stable_top = top;
|
||||
lines = vp_lines;
|
||||
let seqno = pos.pane.get_current_seqno();
|
||||
let mut state = self.pane_state(pos.pane.pane_id());
|
||||
|
||||
(stable_top, lines) = state
|
||||
.logical_line_cache
|
||||
.as_ref()
|
||||
.and_then(|cached| {
|
||||
if cached.seqno == seqno && cached.stable_range == stable_range {
|
||||
Some((cached.top, Rc::clone(&cached.lines)))
|
||||
} else {
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user