A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
perf(cell): make per-cell copies cheap and skip known widths
RoversXe56977cba080
diff --git a/wezterm-cell/src/lib.rs b/wezterm-cell/src/lib.rsindex bb1133eb..7c58632d 100644--- a/wezterm-cell/src/lib.rs+++ b/wezterm-cell/src/lib.rs@@ -629,7 +629,9 @@ impl CellAttributes {}/// Test for image attachments without cloning the attachment list.+ /// Checked before every cell write in a repeated range.#[cfg(feature = "use_image")]+ #[inline]pub fn has_images(&self) -> bool {self.fat.as_ref()@@ -842,7 +844,12 @@ impl TeenyString {}}+// Every cell write drops one of these and copies another. Without LTO (the+// release profile that Linux and Windows ship) each was a call across crates+// per cell, a large share of filling or erasing a row; the inline-string+// checks are small enough to inline.impl Drop for TeenyString {+ #[inline]fn drop(&mut self) {if !Self::is_marker_bit_set(self.0) {let vec = unsafe { Box::from_raw(self.0 as *mut usize as *mut TeenyStringHeap) };@@ -852,6 +859,7 @@ impl Drop for TeenyString {}impl core::clone::Clone for TeenyString {+ #[inline]fn clone(&self) -> Self {if Self::is_marker_bit_set(self.0) {Self(self.0)@@ -859,6 +867,17 @@ impl core::clone::Clone for TeenyString {Self::from_str(self.str(), None, None)}}++ /// An inline string is a plain word: overwriting one frees nothing and+ /// copying one allocates nothing.+ #[inline]+ fn clone_from(&mut self, source: &Self) {+ if Self::is_marker_bit_set(self.0) && Self::is_marker_bit_set(source.0) {+ self.0 = source.0;+ } else {+ *self = source.clone();+ }+ }}impl core::cmp::PartialEq for TeenyString {@@ -1131,6 +1150,38 @@ pub fn grapheme_column_width(s: &str, version: Option<&UnicodeVersion>) -> usizereturn version.wcwidth(s.as_bytes()[0] as char);}+ // Decomposed Latin text (NFD, as in many macOS file names) is a+ // printable ASCII character followed by combining diacritical marks,+ // U+0300..=U+036F. Those marks have no width and select no emoji+ // presentation in any Unicode version, so the base decides: one cell.+ // Configured cell widths may say otherwise, so they take the general+ // path. `decomposed_latin_matches_the_general_path` checks this.+ #[cfg(feature = "std")]+ let custom_widths = version.cell_widths.is_some();+ #[cfg(not(feature = "std"))]+ let custom_widths = false;+ if !custom_widths && is_ascii_with_combining_diacritics(s.as_bytes()) {+ return 1;+ }++ general_column_width(s, version)+}++/// A printable ASCII character followed by at least one combining+/// diacritical mark, U+0300..=U+036F (UTF-8 `CC 80..=BF` or `CD 80..=AF`).+fn is_ascii_with_combining_diacritics(bytes: &[u8]) -> bool {+ let Some((base, marks)) = bytes.split_first() else {+ return false;+ };+ (b' '..=b'~').contains(base)+ && !marks.is_empty()+ && marks.len() % 2 == 0+ && marks+ .chunks_exact(2)+ .all(|mark| matches!(mark, [0xcc, 0x80..=0xbf] | [0xcd, 0x80..=0xaf]))+}++fn general_column_width(s: &str, version: &UnicodeVersion) -> usize {// Slow path: `s.chars()` will dominate and pull up the minimum// runtime to ~20nsif version.version >= 14 {@@ -1191,6 +1242,64 @@ mod test {}}+ #[test]+ fn decomposed_latin_matches_the_general_path() {+ let mut versions = vec![];+ for version in [8, 9, 14] {+ for ambiguous_are_wide in [false, true] {+ let mut v = UnicodeVersion::new(version);+ v.ambiguous_are_wide = ambiguous_are_wide;+ versions.push(v);+ }+ }+ let check = |s: &str| {+ assert!(is_ascii_with_combining_diacritics(s.as_bytes()), "{s:?}");+ for version in &versions {+ assert_eq!(+ grapheme_column_width(s, Some(version)),+ general_column_width(s, version),+ "{s:?} in Unicode {} (ambiguous wide: {})",+ version.version,+ version.ambiguous_are_wide+ );+ }+ };+ for base in b' '..=b'~' {+ for mark in '\u{300}'..='\u{36f}' {+ for count in 1..=3 {+ let s: String = core::iter::once(base as char)+ .chain(core::iter::repeat(mark).take(count))+ .collect();+ check(&s);+ }+ }+ }+ for base in ['a', ' '] {+ for first in '\u{300}'..='\u{36f}' {+ for second in '\u{300}'..='\u{36f}' {+ check(&[base, first, second].iter().collect::<String>());+ }+ }+ }+ // Neighbouring text keeps the general path.+ for s in [+ "a",+ "ab",+ "\u{7f}\u{301}",+ "\u{1f}\u{301}",+ "a\u{2ff}",+ "a\u{36f}\u{370}",+ "a\u{301}\u{fe0f}",+ "\u{e9}\u{301}",+ ] {+ assert!(!is_ascii_with_combining_diacritics(s.as_bytes()), "{s:?}");+ }+ // Configured widths still apply to the marks.+ let mut custom = UnicodeVersion::new(14);+ custom.cell_widths = Some(Arc::new([(0x301, 1u8)].into_iter().collect()));+ assert_eq!(grapheme_column_width("a\u{301}", Some(&custom)), 2);+ }+#[test]fn copies_share_extended_attributes_until_one_changes() {let link = Arc::new(Hyperlink::new("https://example.com"));diff --git a/wezterm-surface/src/line/line.rs b/wezterm-surface/src/line/line.rsindex 83b28aa9..5216d561 100644--- a/wezterm-surface/src/line/line.rs+++ b/wezterm-surface/src/line/line.rs@@ -1003,8 +1003,12 @@ impl Line {if end > cells.len() {cells.resize_with(end, Cell::blank);}- for (offset, byte) in text.bytes().enumerate().skip(1) {- cells.set_cell(idx + offset, Cell::new(byte as char, attr.clone()), false);+ // Printable ASCII (checked above) is one column wide in every+ // Unicode version; don't look the width up per character.+ for offset in 1..text.len() {+ let cell =+ Cell::new_grapheme_with_width(&text[offset..offset + 1], 1, attr.clone());+ cells.set_cell(idx + offset, cell, false);}}_ => {