Improve terminal rendering performance (#33345)

Closes #18263

Improvements:

• **Batch text rendering** - Combine adjacent cells with identical
styling into single text runs to reduce draw calls
• **Throttle hyperlink searches** - Limit hyperlink detection to every
100ms or when mouse moves >5px to reduce CPU usage
• **Pre-allocate collections** - Use `Vec::with_capacity()` for cells,
runs, and regions to minimize reallocations
• **Optimize background regions** - Merge adjacent background rectangles
to reduce number of draw operations
• **Cache selection text** - Only compute terminal selection string when
selection exists

Release Notes:

- Improved terminal rendering performance.

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
Alisina Bahadori 2025-07-08 11:05:01 -04:00 committed by GitHub
parent bcac748c2b
commit 925464cfc6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 609 additions and 177 deletions

View file

@ -357,6 +357,7 @@ impl WindowTextSystem {
text: SharedString,
font_size: Pixels,
runs: &[TextRun],
force_width: Option<Pixels>,
) -> ShapedLine {
debug_assert!(
text.find('\n').is_none(),
@ -384,7 +385,7 @@ impl WindowTextSystem {
});
}
let layout = self.layout_line(&text, font_size, runs);
let layout = self.layout_line(&text, font_size, runs, force_width);
ShapedLine {
layout,
@ -524,6 +525,7 @@ impl WindowTextSystem {
text: Text,
font_size: Pixels,
runs: &[TextRun],
force_width: Option<Pixels>,
) -> Arc<LineLayout>
where
Text: AsRef<str>,
@ -544,9 +546,9 @@ impl WindowTextSystem {
});
}
let layout = self
.line_layout_cache
.layout_line(text, font_size, &font_runs);
let layout =
self.line_layout_cache
.layout_line_internal(text, font_size, &font_runs, force_width);
font_runs.clear();
self.font_runs_pool.lock().push(font_runs);