mirror of
https://github.com/wez/wezterm.git
synced 2024-12-23 05:12:40 +03:00
perf: adjust clustering when bidi is disabled
When a line is rapidly updated with only some of the cells being actually changed (eg: progress counter or other status being frequently updated), it is desirable to avoid paying the cost of shaping the entire line. When bidi is not enabled we can assume that it is safe to break clusters on whitespace boundaries. Doing so allows each of those whitespace separated words to be shaped and potentially cached independently, which reduces the amount of CPU time spent for the whole line. This commit just adjusts the clustering, which reduces the CPU utilization a bit. refs: https://github.com/wez/wezterm/issues/2701
This commit is contained in:
parent
0516b61f62
commit
831eda86b9
@ -102,17 +102,29 @@ impl CellCluster {
|
|||||||
// the terminal is wide and a long series of short lines are printed;
|
// the terminal is wide and a long series of short lines are printed;
|
||||||
// the shaper can cache the few variations of trailing whitespace
|
// the shaper can cache the few variations of trailing whitespace
|
||||||
// and focus on shaping the shorter cluster sequences.
|
// and focus on shaping the shorter cluster sequences.
|
||||||
|
// Or:
|
||||||
|
// when bidi is disabled, force break on whitespace boundaries.
|
||||||
|
// This reduces shaping load in the case where is a line is
|
||||||
|
// updated continually, but only a portion of it changes
|
||||||
|
// (eg: progress counter).
|
||||||
|
let was_whitespace = whitespace_run > 0;
|
||||||
if cell_str == " " {
|
if cell_str == " " {
|
||||||
whitespace_run += 1;
|
whitespace_run += 1;
|
||||||
} else {
|
} else {
|
||||||
whitespace_run = 0;
|
whitespace_run = 0;
|
||||||
only_whitespace = false;
|
only_whitespace = false;
|
||||||
}
|
}
|
||||||
if !only_whitespace && whitespace_run > 2 {
|
|
||||||
|
let force_break = (!only_whitespace && whitespace_run > 2)
|
||||||
|
|| (!only_whitespace && bidi_hint.is_none() && was_whitespace);
|
||||||
|
|
||||||
|
if force_break {
|
||||||
clusters.push(last);
|
clusters.push(last);
|
||||||
|
|
||||||
only_whitespace = cell_str == " ";
|
only_whitespace = cell_str == " ";
|
||||||
|
if whitespace_run > 0 {
|
||||||
whitespace_run = 1;
|
whitespace_run = 1;
|
||||||
|
}
|
||||||
Some(CellCluster::new(
|
Some(CellCluster::new(
|
||||||
hint,
|
hint,
|
||||||
presentation,
|
presentation,
|
||||||
|
@ -128,7 +128,6 @@ mod test {
|
|||||||
use crate::shapecache::{GlyphPosition, ShapedInfo};
|
use crate::shapecache::{GlyphPosition, ShapedInfo};
|
||||||
use crate::utilsprites::RenderMetrics;
|
use crate::utilsprites::RenderMetrics;
|
||||||
use config::{FontAttributes, TextStyle};
|
use config::{FontAttributes, TextStyle};
|
||||||
use k9::assert_equal as assert_eq;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use termwiz::cell::CellAttributes;
|
use termwiz::cell::CellAttributes;
|
||||||
use termwiz::surface::{Line, SEQ_ZERO};
|
use termwiz::surface::{Line, SEQ_ZERO};
|
||||||
@ -149,11 +148,12 @@ mod test {
|
|||||||
{
|
{
|
||||||
let line = Line::from_text(text, &CellAttributes::default(), SEQ_ZERO, None);
|
let line = Line::from_text(text, &CellAttributes::default(), SEQ_ZERO, None);
|
||||||
eprintln!("{:?}", line);
|
eprintln!("{:?}", line);
|
||||||
let cell_clusters = line.cluster(None);
|
let mut all_infos = vec![];
|
||||||
assert_eq!(cell_clusters.len(), 1);
|
let mut all_glyphs = vec![];
|
||||||
let cluster = &cell_clusters[0];
|
|
||||||
|
for cluster in line.cluster(None) {
|
||||||
let presentation_width = PresentationWidth::with_cluster(&cluster);
|
let presentation_width = PresentationWidth::with_cluster(&cluster);
|
||||||
let infos = font
|
let mut infos = font
|
||||||
.shape(
|
.shape(
|
||||||
&cluster.text,
|
&cluster.text,
|
||||||
|| {},
|
|| {},
|
||||||
@ -164,7 +164,7 @@ mod test {
|
|||||||
Some(&presentation_width),
|
Some(&presentation_width),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let glyphs = infos
|
let mut glyphs = infos
|
||||||
.iter()
|
.iter()
|
||||||
.map(|info| {
|
.map(|info| {
|
||||||
let cell_idx = cluster.byte_to_cell_idx(info.cluster as usize);
|
let cell_idx = cluster.byte_to_cell_idx(info.cluster as usize);
|
||||||
@ -188,9 +188,13 @@ mod test {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
eprintln!("infos: {:#?}", infos);
|
all_infos.append(&mut infos);
|
||||||
eprintln!("glyphs: {:#?}", glyphs);
|
all_glyphs.append(&mut glyphs);
|
||||||
ShapedInfo::process(&infos, &glyphs)
|
}
|
||||||
|
|
||||||
|
eprintln!("infos: {:#?}", all_infos);
|
||||||
|
eprintln!("glyphs: {:#?}", all_glyphs);
|
||||||
|
ShapedInfo::process(&all_infos, &all_glyphs)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|p| p.pos)
|
.map(|p| p.pos)
|
||||||
.collect()
|
.collect()
|
||||||
|
Loading…
Reference in New Issue
Block a user