Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 1 addition & 130 deletions benches/bench_compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,132 +13,6 @@ fn cfg() -> Criterion {
.sample_size(10)
}

fn bench_compose_table_creation(c: &mut Criterion) {
let mut group = c.benchmark_group("compose/table_creation");
let locale = COMPOSE_LOCALE;

group.bench_function("wkb", |b| {
b.iter(|| {
let resolved = xkb_core::compose::resolve_compose_file(black_box(locale));
if let Some(subpath) = resolved {
let path = std::path::Path::new("/usr/share/X11/locale").join(&subpath);
let composer = wkb::testing::compose_parse::load_compose_from_path(&path);
black_box(composer);
}
});
});

group.bench_function("xkbcommon", |b| {
use xkbcommon::xkb;
let ctx = xkb::Context::new(xkb::CONTEXT_NO_FLAGS);
let locale_os = std::ffi::OsStr::new(locale);
b.iter(|| {
let table = xkb::compose::Table::new_from_locale(
&ctx,
locale_os,
xkb::compose::COMPILE_NO_FLAGS,
);
let _ = black_box(table);
});
});

group.bench_function("xkbcommon-dl", |b| {
let xkb = xkbcommon_dl::xkbcommon_handle();
let xkb_compose = xkbcommon_dl::xkbcommon_compose_handle();
let ctx =
unsafe { (xkb.xkb_context_new)(xkbcommon_dl::xkb_context_flags::XKB_CONTEXT_NO_FLAGS) };
let c_locale = CString::new(locale).unwrap();
b.iter(|| {
let table = unsafe {
(xkb_compose.xkb_compose_table_new_from_locale)(
ctx,
c_locale.as_ptr(),
xkbcommon_dl::xkb_compose_compile_flags::XKB_COMPOSE_COMPILE_NO_FLAGS,
)
};
black_box(table);
if !table.is_null() {
unsafe { (xkb_compose.xkb_compose_table_unref)(table) };
}
});
unsafe { (xkb.xkb_context_unref)(ctx) };
});

group.finish();
}

fn bench_compose_state_creation(c: &mut Criterion) {
let mut group = c.benchmark_group("compose/state_creation");
let locale = COMPOSE_LOCALE;

{
let resolved = xkb_core::compose::resolve_compose_file(locale);
let path = resolved.map(|s| {
std::path::Path::new("/usr/share/X11/locale")
.join(&s)
.to_path_buf()
});
group.bench_function("wkb", |b| {
b.iter(|| {
if let Some(ref p) = path {
let composer = wkb::testing::compose_parse::load_compose_from_path(p);
black_box(composer);
}
});
});
}

{
use xkbcommon::xkb;
let ctx = xkb::Context::new(xkb::CONTEXT_NO_FLAGS);
let locale_os = std::ffi::OsStr::new(locale);
let table =
xkb::compose::Table::new_from_locale(&ctx, locale_os, xkb::compose::COMPILE_NO_FLAGS)
.expect("compose table");
group.bench_function("xkbcommon", |b| {
b.iter(|| {
let state = xkb::compose::State::new(&table, xkb::compose::STATE_NO_FLAGS);
black_box(state);
});
});
}

{
let xkb = xkbcommon_dl::xkbcommon_handle();
let xkb_compose = xkbcommon_dl::xkbcommon_compose_handle();
let ctx =
unsafe { (xkb.xkb_context_new)(xkbcommon_dl::xkb_context_flags::XKB_CONTEXT_NO_FLAGS) };
let c_locale = CString::new(locale).unwrap();
let table = unsafe {
(xkb_compose.xkb_compose_table_new_from_locale)(
ctx,
c_locale.as_ptr(),
xkbcommon_dl::xkb_compose_compile_flags::XKB_COMPOSE_COMPILE_NO_FLAGS,
)
};
group.bench_function("xkbcommon-dl", |b| {
b.iter(|| {
let state = unsafe {
(xkb_compose.xkb_compose_state_new)(
table,
xkbcommon_dl::xkb_compose_state_flags::XKB_COMPOSE_STATE_NO_FLAGS,
)
};
black_box(state);
if !state.is_null() {
unsafe { (xkb_compose.xkb_compose_state_unref)(state) };
}
});
});
unsafe {
(xkb_compose.xkb_compose_table_unref)(table);
(xkb.xkb_context_unref)(ctx);
};
}

group.finish();
}

fn bench_compose_feed(c: &mut Criterion) {
let mut group = c.benchmark_group("compose/feed");

Expand Down Expand Up @@ -244,9 +118,6 @@ fn bench_compose_feed(c: &mut Criterion) {
criterion_group! {
name = benches;
config = cfg();
targets =
bench_compose_table_creation,
bench_compose_state_creation,
bench_compose_feed,
targets = bench_compose_feed,
}
criterion_main!(benches);
27 changes: 5 additions & 22 deletions benches/bench_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ fn bench_key_update(c: &mut Criterion) {
group.finish();
}

// ── key/get_utf8 ───────────────────────────────────────────────────────
// ── key/get_char ───────────────────────────────────────────────────────

fn bench_key_get_utf8(c: &mut Criterion) {
let mut group = c.benchmark_group("key/get_utf8");
fn bench_key_get_char(c: &mut Criterion) {
let mut group = c.benchmark_group("key/get_char");

for case in KEY_CASES {
for (lid, locale, variant) in layouts_for_case(case.name) {
Expand Down Expand Up @@ -309,24 +309,7 @@ fn bench_key_get_sym(c: &mut Criterion) {
|wb: &mut wkb::WKB, code: u32, down: bool, dir: KeyDirection| {
wb.update_key(code, dir);
if down {
black_box(wb.key_char(black_box(code)));
}
}
);

bench_xkb!(
group,
bid,
locale,
variant,
case,
|st: &mut xkbcommon::xkb::State,
kc: xkbcommon::xkb::Keycode,
down: bool,
dir: xkbcommon::xkb::KeyDirection| {
st.update_key(kc, dir);
if down {
black_box(st.key_get_one_sym(black_box(kc)));
black_box(wb.state_keysym(black_box(code)));
}
}
);
Expand Down Expand Up @@ -358,7 +341,7 @@ criterion_group! {
config = cfg();
targets =
bench_key_update,
bench_key_get_utf8,
bench_key_get_char,
bench_key_get_sym,
}
criterion_main!(benches);
80 changes: 77 additions & 3 deletions benches/bench_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,85 @@ fn cfg() -> Criterion {
.sample_size(10)
}

fn bench_full_setup(c: &mut Criterion) {
let mut group = c.benchmark_group("full_setup");
fn bench_setup_no_compose(c: &mut Criterion) {
let mut group = c.benchmark_group("setup/no_compose");
let locale = "us";

group.bench_function("wkb", |b| {
// Temporarily unset locale env vars so compose is not loaded
let saved = std::env::var("LC_ALL").ok();
std::env::set_var("LC_ALL", "C");
b.iter(|| {
let wkb: wkb::WKB =
wkb::WKB::new_from_names("", "", black_box(locale), "", None).unwrap();
black_box(wkb);
});
if let Some(v) = saved {
std::env::set_var("LC_ALL", v);
} else {
std::env::remove_var("LC_ALL");
}
});

group.bench_function("xkbcommon", |b| {
use xkbcommon::xkb;
b.iter(|| {
let ctx = xkb::Context::new(xkb::CONTEXT_NO_FLAGS);
let km = xkb::Keymap::new_from_names(
&ctx,
"evdev",
"",
black_box(locale),
"",
None,
xkb::KEYMAP_COMPILE_NO_FLAGS,
)
.expect("keymap");
let st = xkb::State::new(&km);
let _ = black_box((ctx, km, st));
});
});

group.bench_function("xkbcommon-dl", |b| {
let xkb = xkbcommon_dl::xkbcommon_handle();
b.iter(|| {
let ctx = unsafe {
(xkb.xkb_context_new)(xkbcommon_dl::xkb_context_flags::XKB_CONTEXT_NO_FLAGS)
};
let rmlvo = xkbcommon_dl::xkb_rule_names {
rules: c"evdev".as_ptr(),
model: ptr::null(),
layout: c"us".as_ptr(),
variant: ptr::null(),
options: ptr::null(),
};
let km = unsafe {
(xkb.xkb_keymap_new_from_names)(
ctx,
&rmlvo,
xkbcommon_dl::xkb_keymap_compile_flags::XKB_KEYMAP_COMPILE_NO_FLAGS,
)
};
let st = unsafe { (xkb.xkb_state_new)(km) };
black_box((ctx, km, st));
unsafe {
(xkb.xkb_state_unref)(st);
(xkb.xkb_keymap_unref)(km);
(xkb.xkb_context_unref)(ctx);
}
});
});

group.finish();
}

fn bench_setup_with_compose(c: &mut Criterion) {
let mut group = c.benchmark_group("setup/with_compose");
let locale = "us";

group.bench_function("wkb", |b| {
// Ensure compose locale resolves
std::env::set_var("LC_ALL", COMPOSE_LOCALE);
b.iter(|| {
let wkb: wkb::WKB =
wkb::WKB::new_from_names("", "", black_box(locale), "", None).unwrap();
Expand Down Expand Up @@ -116,6 +190,6 @@ fn bench_full_setup(c: &mut Criterion) {
criterion_group! {
name = benches;
config = cfg();
targets = bench_full_setup,
targets = bench_setup_no_compose, bench_setup_with_compose,
}
criterion_main!(benches);
2 changes: 1 addition & 1 deletion examples/bench_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ fn run_workload_xkbcommon_compat() -> u64 {
variant: variant.unwrap_or("").to_string(),
options: String::new(),
};
let km = ctx.keymap_from_names(&rmlvo).expect("keymap");
let km = ctx.clone().keymap_from_names(&rmlvo).expect("keymap");
let mut st = km.new_state().expect("state");

for case in KEY_CASES {
Expand Down
86 changes: 0 additions & 86 deletions examples/profile_setup.rs

This file was deleted.

5 changes: 3 additions & 2 deletions src/composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ impl Composer {
let last = self.pending.len() - 1;

for token in &self.pending[..last] {
if let Token::Char(c) = token {
s.push(*c);
match token {
Token::Char(c) => s.push(*c),
Token::Compose => {}
}
}

Expand Down
Loading