From 8d3a4d02ee82f796031309d0b6c54ae893772ffe Mon Sep 17 00:00:00 2001 From: Eivind Gamst Date: Mon, 27 Apr 2026 14:50:38 +0200 Subject: [PATCH 1/2] Show more benchmarks --- Cargo.toml | 1 + bench.sh | 4 ++-- scripts/generate_benchmark_table.js | 15 ++++++++------- src/composer.rs | 10 ++++++---- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8fef9c30..7bb0c251 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ testing = ["xkb"] [dependencies] xkb-core = { version = "0.2.0", path = "xkb-core", optional = true } +smol_str = "0.3" [dev-dependencies] wkb = { package = "wayland-keyboard", path = ".", features = ["testing"] } diff --git a/bench.sh b/bench.sh index 16fe982a..398203ce 100755 --- a/bench.sh +++ b/bench.sh @@ -12,9 +12,9 @@ echo "" # ── 1. Speed Benchmarks (Criterion) ───────────────────────────────── echo "▶ [1/3] Speed benchmarks (Criterion)" -echo " Running: cargo bench --bench bench_speed" +echo " Running: cargo bench --bench bench_setup --bench bench_key --bench bench_compose" echo "" -cargo bench --bench bench_speed 2>&1 | tee "$RESULTS_DIR/speed.txt" +cargo bench --bench bench_setup --bench bench_key --bench bench_compose 2>&1 | tee "$RESULTS_DIR/speed.txt" echo "" # ── 2. Memory Benchmarks ──────────────────────────────────────────── diff --git a/scripts/generate_benchmark_table.js b/scripts/generate_benchmark_table.js index 43dca678..af4f1d3f 100644 --- a/scripts/generate_benchmark_table.js +++ b/scripts/generate_benchmark_table.js @@ -59,14 +59,15 @@ function generateSpeedTable() { const groups = fs.readdirSync(CRITERION_DIR) .filter(d => !d.startsWith('.') && d !== 'report'); - // Criterion stores groups with '_' separators in directory names + // Criterion stores group names using '/' as directory separators. + // The benchmark groups are defined in bench_setup.rs, bench_key.rs, bench_compose.rs. const interesting = [ - { dir: 'full_setup', label: 'Full setup' }, - { dir: 'key_update', label: 'Key update' }, - { dir: 'key_get_utf8', label: 'Get UTF-8' }, - { dir: 'key_get_sym', label: 'Get keysym' }, - { dir: 'compose_setup', label: 'Compose setup', combine: ['compose_table_creation', 'compose_state_creation'] }, - { dir: 'compose_feed', label: 'Compose feed' }, + { dir: 'setup/with_compose', label: 'Full setup (with compose)' }, + { dir: 'setup/no_compose', label: 'Setup (no compose)' }, + { dir: 'key/update', label: 'Key update' }, + { dir: 'key/get_char', label: 'Key get char' }, + { dir: 'key/get_sym', label: 'Key get sym' }, + { dir: 'compose/feed', label: 'Compose feed' }, ]; const rows = []; diff --git a/src/composer.rs b/src/composer.rs index ad018070..457387b4 100644 --- a/src/composer.rs +++ b/src/composer.rs @@ -1,3 +1,5 @@ +use smol_str::SmolStr; + /// Token fed into the composer: either a regular character or a Compose key press #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Token { @@ -8,7 +10,7 @@ pub enum Token { #[derive(Debug, Clone, PartialEq, Eq)] pub enum ComposeState { Idle(char), - Composing(String), + Composing(SmolStr), Finished(char), Cancelled, } @@ -84,9 +86,9 @@ impl Composer { /// Returns an opinionated display string of the in-progress compose sequence. /// Compose key shows as `·` if it is the last token pressed. /// Characters show as themselves. - pub fn pending_string(&self) -> String { + pub fn pending_string(&self) -> SmolStr { if self.pending.is_empty() { - return String::new(); + return SmolStr::default(); } let mut s = String::with_capacity(self.pending.len()); @@ -104,7 +106,7 @@ impl Composer { Token::Char(c) => s.push(c), } - s + SmolStr::new(&s) } #[inline] From fb89c5981cbbf49aaf5aa45dc3f346c844010c1b Mon Sep 17 00:00:00 2001 From: Eivind Gamst Date: Mon, 27 Apr 2026 14:58:29 +0200 Subject: [PATCH 2/2] compact string! --- Cargo.toml | 2 +- src/composer.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7bb0c251..822d0291 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ testing = ["xkb"] [dependencies] xkb-core = { version = "0.2.0", path = "xkb-core", optional = true } -smol_str = "0.3" +compact_str = "0.8" [dev-dependencies] wkb = { package = "wayland-keyboard", path = ".", features = ["testing"] } diff --git a/src/composer.rs b/src/composer.rs index 457387b4..d2ad120f 100644 --- a/src/composer.rs +++ b/src/composer.rs @@ -1,4 +1,4 @@ -use smol_str::SmolStr; +use compact_str::CompactString; /// Token fed into the composer: either a regular character or a Compose key press #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -10,7 +10,7 @@ pub enum Token { #[derive(Debug, Clone, PartialEq, Eq)] pub enum ComposeState { Idle(char), - Composing(SmolStr), + Composing(CompactString), Finished(char), Cancelled, } @@ -86,12 +86,12 @@ impl Composer { /// Returns an opinionated display string of the in-progress compose sequence. /// Compose key shows as `·` if it is the last token pressed. /// Characters show as themselves. - pub fn pending_string(&self) -> SmolStr { + pub fn pending_string(&self) -> CompactString { if self.pending.is_empty() { - return SmolStr::default(); + return CompactString::default(); } - let mut s = String::with_capacity(self.pending.len()); + let mut s = CompactString::with_capacity(self.pending.len()); let last = self.pending.len() - 1; for token in &self.pending[..last] { @@ -106,7 +106,7 @@ impl Composer { Token::Char(c) => s.push(c), } - SmolStr::new(&s) + s } #[inline]