aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-20 03:38:20 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-20 03:42:06 +0800
commit0ee5d865a1eaf8b409c2b310ab16ee5f42a0f14a (patch)
treecc409abf22f6e9d5fd5313da1f5e89488a5b2713
parent5678e0ba37ce2c5c8161f0d48505e7993967e30c (diff)
feat: add dispatch benchmark subproject
-rw-r--r--.cargo/config.toml2
-rw-r--r--dev/bench/dispatch/Cargo.lock444
-rw-r--r--dev/bench/dispatch/Cargo.toml16
-rw-r--r--dev/bench/dispatch/build.rs153
-rw-r--r--dev/bench/dispatch/src/main.rs183
-rw-r--r--mingling_macros/src/systems/dispatch_auto.rs1
-rw-r--r--mingling_macros/src/systems/dispatch_list_gen.rs1
-rw-r--r--mingling_macros/src/systems/dispatch_phf_gen.rs1
-rw-r--r--mingling_macros/src/systems/dispatch_tree_gen.rs1
9 files changed, 798 insertions, 4 deletions
diff --git a/.cargo/config.toml b/.cargo/config.toml
index 8a25d59..dbaddc5 100644
--- a/.cargo/config.toml
+++ b/.cargo/config.toml
@@ -6,3 +6,5 @@ target-dir = "./.temp/target"
[alias]
ci = "run --manifest-path dev/ci/Cargo.toml --bin ci --quiet --"
dev_tool = "run --manifest-path dev/run/Cargo.toml --quiet --bin "
+
+dispatch-bench = "run --release --quiet --manifest-path dev/bench/dispatch/Cargo.toml"
diff --git a/dev/bench/dispatch/Cargo.lock b/dev/bench/dispatch/Cargo.lock
new file mode 100644
index 0000000..2466e01
--- /dev/null
+++ b/dev/bench/dispatch/Cargo.lock
@@ -0,0 +1,444 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "cfg-if"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
+
+[[package]]
+name = "csv"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "52cd9d68cf7efc6ddfaaee42e7288d3a99d613d4b50f76ce9827ae0c6e14f938"
+dependencies = [
+ "csv-core",
+ "itoa",
+ "ryu",
+ "serde_core",
+]
+
+[[package]]
+name = "csv-core"
+version = "0.1.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "704a3c26996a80471189265814dbc2c257598b96b8a7feae2d31ace646bb9782"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
+name = "dirs-next"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
+dependencies = [
+ "cfg-if",
+ "dirs-sys-next",
+]
+
+[[package]]
+name = "dirs-sys-next"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
+dependencies = [
+ "libc",
+ "redox_users",
+ "winapi",
+]
+
+[[package]]
+name = "encode_unicode"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
+
+[[package]]
+name = "equivalent"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
+
+[[package]]
+name = "getrandom"
+version = "0.2.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "wasi",
+]
+
+[[package]]
+name = "hashbrown"
+version = "0.17.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
+
+[[package]]
+name = "hermit-abi"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c"
+
+[[package]]
+name = "indexmap"
+version = "2.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
+dependencies = [
+ "equivalent",
+ "hashbrown",
+]
+
+[[package]]
+name = "is-terminal"
+version = "0.4.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46"
+dependencies = [
+ "hermit-abi",
+ "libc",
+ "windows-sys",
+]
+
+[[package]]
+name = "itoa"
+version = "1.0.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
+
+[[package]]
+name = "just_fmt"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "91b935090fce9a995a79798a22d523f1742b202f57ad2d8fcab6ad3dff528baf"
+
+[[package]]
+name = "lazy_static"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
+
+[[package]]
+name = "libc"
+version = "0.2.189"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
+
+[[package]]
+name = "libredox"
+version = "0.1.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "28d0a00925a9f930d679b6789b721e3a7f9ed110f41b86d2497caa780c3a070a"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "memchr"
+version = "2.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
+
+[[package]]
+name = "might_be_async"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eca871cea620b07bd2e6da0c883891a25bead698c43a9ab64b0fd663a7a78d5f"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+ "toml",
+]
+
+[[package]]
+name = "mingling"
+version = "0.5.0"
+dependencies = [
+ "mingling_core",
+ "mingling_macros",
+]
+
+[[package]]
+name = "mingling_bench"
+version = "0.1.0"
+dependencies = [
+ "mingling",
+ "mingling_macros",
+ "prettytable-rs",
+]
+
+[[package]]
+name = "mingling_core"
+version = "0.5.0"
+dependencies = [
+ "just_fmt",
+ "might_be_async",
+]
+
+[[package]]
+name = "mingling_macros"
+version = "0.5.0"
+dependencies = [
+ "just_fmt",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
+[[package]]
+name = "prettytable-rs"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eea25e07510aa6ab6547308ebe3c036016d162b8da920dbb079e3ba8acf3d95a"
+dependencies = [
+ "csv",
+ "encode_unicode",
+ "is-terminal",
+ "lazy_static",
+ "term",
+ "unicode-width",
+]
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.107"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.47"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "redox_users"
+version = "0.4.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
+dependencies = [
+ "getrandom",
+ "libredox",
+ "thiserror",
+]
+
+[[package]]
+name = "rustversion"
+version = "1.0.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
+
+[[package]]
+name = "ryu"
+version = "1.0.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
+
+[[package]]
+name = "serde"
+version = "1.0.229"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
+dependencies = [
+ "serde_core",
+]
+
+[[package]]
+name = "serde_core"
+version = "1.0.229"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.229"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 3.0.3",
+]
+
+[[package]]
+name = "serde_spanned"
+version = "0.6.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3"
+dependencies = [
+ "serde",
+]
+
+[[package]]
+name = "syn"
+version = "2.0.119"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "syn"
+version = "3.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "term"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f"
+dependencies = [
+ "dirs-next",
+ "rustversion",
+ "winapi",
+]
+
+[[package]]
+name = "thiserror"
+version = "1.0.69"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
+dependencies = [
+ "thiserror-impl",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "1.0.69"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
+[[package]]
+name = "toml"
+version = "0.8.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362"
+dependencies = [
+ "serde",
+ "serde_spanned",
+ "toml_datetime",
+ "toml_edit",
+]
+
+[[package]]
+name = "toml_datetime"
+version = "0.6.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c"
+dependencies = [
+ "serde",
+]
+
+[[package]]
+name = "toml_edit"
+version = "0.22.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a"
+dependencies = [
+ "indexmap",
+ "serde",
+ "serde_spanned",
+ "toml_datetime",
+ "toml_write",
+ "winnow",
+]
+
+[[package]]
+name = "toml_write"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801"
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
+
+[[package]]
+name = "unicode-width"
+version = "0.1.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
+
+[[package]]
+name = "wasi"
+version = "0.11.1+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
+
+[[package]]
+name = "winapi"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
+dependencies = [
+ "winapi-i686-pc-windows-gnu",
+ "winapi-x86_64-pc-windows-gnu",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
+
+[[package]]
+name = "windows-link"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
+
+[[package]]
+name = "windows-sys"
+version = "0.61.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
+dependencies = [
+ "windows-link",
+]
+
+[[package]]
+name = "winnow"
+version = "0.7.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945"
+dependencies = [
+ "memchr",
+]
diff --git a/dev/bench/dispatch/Cargo.toml b/dev/bench/dispatch/Cargo.toml
new file mode 100644
index 0000000..ed5c46f
--- /dev/null
+++ b/dev/bench/dispatch/Cargo.toml
@@ -0,0 +1,16 @@
+[package]
+name = "mingling_bench"
+version = "0.1.0"
+edition = "2024"
+publish = false
+description = "Workspace-internal dispatch-strategy benchmark: linear list vs char trie vs perfect hash"
+
+[dependencies]
+mingling = { path = "../../../mingling" }
+mingling_macros = { path = "../../../mingling_macros", features = ["bench_support"] }
+prettytable-rs = "0.10"
+
+[profile.release]
+opt-level = 2
+
+[workspace]
diff --git a/dev/bench/dispatch/build.rs b/dev/bench/dispatch/build.rs
new file mode 100644
index 0000000..09eefaa
--- /dev/null
+++ b/dev/bench/dispatch/build.rs
@@ -0,0 +1,153 @@
+//! Generates `generated.rs` — the dispatch benchmark matrix
+//! (command length × command count × command-name type × {dispatch_linear,
+//! dispatch_tree, dispatch_phf}).
+//!
+//! The heavy lifting (dispatch generation) happens inside the `bench_cell!`
+//! proc macro from `mingling_macros` (enabled via its `bench_support`
+//! feature); this script only writes the invocations and the glue.
+
+use std::fmt::Write as _;
+use std::path::Path;
+
+// Full length axis (4/8/16/32) × count {128, 256} × {single, multi,
+// nested4, nested10}, keeping the agreed max-256 / depth-10 bound so the
+// whole matrix compiles in a few minutes.
+const LENGTHS: [usize; 4] = [4, 8, 16, 32];
+const COUNTS: [usize; 2] = [128, 256];
+
+// (label, kind, chain_depth) — chain_depth only applies to the "nested" kind.
+const TYPES: [(&str, &str, usize); 4] = [
+ ("single", "single", 0),
+ ("multi", "multi", 0),
+ ("nested4", "nested", 4),
+ ("nested10", "nested", 10),
+];
+
+const STRATEGIES: [&str; 4] = [
+ "dispatch_linear",
+ "dispatch_tree",
+ "dispatch_phf",
+ "dispatch_auto",
+];
+
+fn zero_pad(i: usize, w: usize) -> String {
+ let s = i.to_string();
+ let mut out = String::with_capacity(w);
+ for _ in 0..w.saturating_sub(s.len()) {
+ out.push('0');
+ }
+ out.push_str(&s);
+ out
+}
+
+fn make_names(len: usize, count: usize, kind: &str, depth: usize) -> Vec<String> {
+ let digits = |n: usize| n.to_string().len();
+ let mut names = Vec::new();
+ match kind {
+ // Single-word commands with no shared prefixes.
+ "single" => {
+ let w = len.saturating_sub(1).max(3).max(digits(count));
+ for i in 0..count {
+ names.push(format!("c{}", zero_pad(i, w)));
+ }
+ }
+ // Two-word commands sharing the first word ("cmd ..."), git-style.
+ "multi" => {
+ let w = len.saturating_sub(4).max(3).max(digits(count));
+ for i in 0..count {
+ names.push(format!("cmd {}", zero_pad(i, w)));
+ }
+ }
+ // Nested-prefix chains of `depth`: base, base w1, base w1 w2, ...
+ // The base word length follows the `len` axis.
+ "nested" => {
+ let groups = count.div_ceil(depth);
+ let bw = len.saturating_sub(1).max(3).max(digits(groups));
+ 'outer: for g in 0..groups {
+ let base = format!("n{}", zero_pad(g, bw));
+ for d in 0..depth {
+ let mut name = base.clone();
+ for k in 1..=d {
+ let _ = write!(name, " w{k}");
+ }
+ names.push(name);
+ if names.len() == count {
+ break 'outer;
+ }
+ }
+ }
+ }
+ _ => unreachable!(),
+ }
+ names
+}
+
+fn entries_tokens(names: &[String]) -> String {
+ names
+ .iter()
+ .enumerate()
+ .map(|(i, n)| format!("\"{n}\" => D{i}"))
+ .collect::<Vec<_>>()
+ .join(", ")
+}
+
+fn main() {
+ let out_dir = std::env::var("OUT_DIR").expect("OUT_DIR is set by cargo");
+ let mut src = String::from("// @generated by mingling_bench/build.rs — do not edit.\n\n");
+ let mut meta = String::new();
+ let mut run_cell = String::new();
+ let mut run_cell_pick = String::new();
+ let mut meta_entries: Vec<String> = Vec::new();
+ let mut cell_id = 0usize;
+
+ for &len in &LENGTHS {
+ for &count in &COUNTS {
+ for &(ty, kind, depth) in &TYPES {
+ let label = format!("len{len:03}_cnt{count:04}_ty_{ty}");
+ let names = make_names(len, count, kind, depth);
+ for &strat in &STRATEGIES {
+ let _ = writeln!(
+ src,
+ "mingling_macros::bench_cell!({strat}, cell_{cell_id:03}, [{}]);\n",
+ entries_tokens(&names)
+ );
+ meta_entries.push(format!(
+ "(\"{label}\", \"{strat}\", cell_{cell_id:03}::NAMES),"
+ ));
+ let _ = writeln!(
+ run_cell,
+ " {cell_id} => cell_{cell_id:03}::measure(hits, misses),"
+ );
+ let _ = writeln!(
+ run_cell_pick,
+ " {cell_id} => cell_{cell_id:03}::STRATEGY,"
+ );
+ cell_id += 1;
+ }
+ }
+ }
+ }
+
+ let _ = writeln!(
+ meta,
+ "pub static CELL_META: &[(&str, &str, &'static [&'static str])] = &[\n{}\n];",
+ meta_entries.join("\n")
+ );
+ let _ = writeln!(
+ src,
+ "{meta}\n\
+ pub fn run_cell(id: usize, hits: &[Vec<String>], misses: &[Vec<String>]) -> (f64, f64) {{\n\
+ match id {{\n\
+ {run_cell} _ => panic!(\"unknown cell {{id}}\"),\n\
+ }}\n\
+ }}\n\
+ pub fn run_cell_pick(id: usize) -> &'static str {{\n\
+ match id {{\n\
+ {run_cell_pick} _ => \"\",\n\
+ }}\n\
+ }}"
+ );
+
+ std::fs::write(Path::new(&out_dir).join("generated.rs"), src)
+ .expect("failed to write generated.rs");
+}
diff --git a/dev/bench/dispatch/src/main.rs b/dev/bench/dispatch/src/main.rs
new file mode 100644
index 0000000..431784d
--- /dev/null
+++ b/dev/bench/dispatch/src/main.rs
@@ -0,0 +1,183 @@
+//! Dispatch-strategy matrix benchmark: linear list vs char trie vs perfect
+//! hash, plus the "auto" strategy (which picks one of the three from the
+//! command table — the summary checks it against the per-cell minimum).
+//!
+//! Build & run (workspace-internal, `-O`):
+//! ```bash
+//! cargo run --release --manifest-path dev/bench/dispatch/Cargo.toml
+//! ```
+
+#![allow(dead_code, clippy::all)]
+
+use prettytable::format::Alignment;
+use prettytable::{Cell, Row, Table};
+
+/// Minimal dispatch surface implemented by every generated cell so the four
+/// strategies can be benchmarked through a uniform call.
+pub trait BenchDispatch {
+ type Enum;
+ fn dispatch_args(
+ raw: &[String],
+ ) -> Result<::mingling::AnyOutput<Self::Enum>, ::mingling::error::ProgramInternalExecuteError>;
+ fn build_entry_fallback(args: Vec<String>) -> ::mingling::AnyOutput<Self::Enum>;
+}
+
+include!(concat!(env!("OUT_DIR"), "/generated.rs"));
+
+const N_STRATS: usize = 4; // linear, trie, phf, auto
+
+fn right(v: f64) -> Cell {
+ Cell::new_align(&format!("{v:.1}"), Alignment::RIGHT)
+}
+
+fn right2(v: f64) -> Cell {
+ Cell::new_align(&format!("{v:.2}"), Alignment::RIGHT)
+}
+
+fn left(s: &str) -> Cell {
+ Cell::new(s)
+}
+
+fn main() {
+ println!("dispatch matrix — ns/op (lower is better), best of 5×50k, rustc -O");
+ println!();
+
+ let results: Vec<(String, String, f64, f64)> = CELL_META
+ .iter()
+ .enumerate()
+ .map(|(id, (label, strat, names))| {
+ let hits: Vec<Vec<String>> = names
+ .iter()
+ .map(|name| {
+ let mut v: Vec<String> = name.split(' ').map(str::to_string).collect();
+ v.push("argA".into());
+ v.push("argB".into());
+ v
+ })
+ .collect();
+ let misses: Vec<Vec<String>> = vec![
+ vec!["qqq".into(), "zzz".into()],
+ vec!["qqq".into(), "zzz".into(), "argA".into()],
+ vec!["qqq".into()],
+ ];
+ let (h, m) = run_cell(id, &hits, &misses);
+ (label.to_string(), strat.to_string(), h, m)
+ })
+ .collect();
+
+ let mut table = Table::new();
+ table.set_format(*prettytable::format::consts::FORMAT_BOX_CHARS);
+ table.set_titles(Row::new(vec![
+ left("cell"),
+ left("── hit ──"),
+ left(""),
+ left(""),
+ left(""),
+ left("── miss ──"),
+ left(""),
+ left(""),
+ left(""),
+ ]));
+ table.add_row(Row::new(vec![
+ left(""),
+ left("lin"),
+ left("trie"),
+ left("phf"),
+ left("auto"),
+ left("lin"),
+ left("trie"),
+ left("phf"),
+ left("auto"),
+ ]));
+
+ let mut geo_hit = [1.0f64; N_STRATS];
+ let mut geo_miss = [1.0f64; N_STRATS];
+ let mut wins = [0usize; N_STRATS];
+ let mut auto_optimal = 0usize;
+ let mut auto_within5 = 0usize;
+ let mut cells = 0usize;
+ let mut auto_picks = [0usize; N_STRATS]; // auto's own selection counts
+
+ for (chunk_idx, chunk) in results.chunks(N_STRATS).enumerate() {
+ let label = &chunk[0].0;
+ let hit: Vec<f64> = chunk.iter().map(|c| c.2).collect();
+ let miss: Vec<f64> = chunk.iter().map(|c| c.3).collect();
+ table.add_row(Row::new(vec![
+ left(label),
+ right(hit[0]),
+ right(hit[1]),
+ right(hit[2]),
+ right(hit[3]),
+ right(miss[0]),
+ right(miss[1]),
+ right(miss[2]),
+ right(miss[3]),
+ ]));
+ for s in 0..N_STRATS {
+ geo_hit[s] *= hit[s];
+ geo_miss[s] *= miss[s];
+ }
+ // Per-cell winner by hit×miss geomean among the three explicit
+ // strategies.
+ let gm: Vec<f64> = (0..N_STRATS).map(|s| (hit[s] * miss[s]).sqrt()).collect();
+ let mut best_idx = 0usize;
+ for s in 1..3 {
+ if gm[s] < gm[best_idx] {
+ best_idx = s;
+ }
+ }
+ let best_idx_gm = gm[best_idx];
+ wins[best_idx] += 1;
+ // The auto cell (last of the four) exposes its chosen strategy; check
+ // it against the measured minimum.
+ let auto_id = chunk_idx * N_STRATS + (N_STRATS - 1);
+ let pick_idx = match run_cell_pick(auto_id) {
+ "dispatch_linear" => 0,
+ "dispatch_tree" => 1,
+ _ => 2,
+ };
+ auto_picks[pick_idx] += 1;
+ if pick_idx == best_idx {
+ auto_optimal += 1;
+ }
+ // Identical generated code measures up to ~10 ns apart across cells,
+ // so also count selections within 5% of the measured minimum.
+ if gm[3] <= best_idx_gm * 1.05 {
+ auto_within5 += 1;
+ }
+ cells += 1;
+ }
+
+ let n = cells as f64;
+ table.add_row(Row::new(vec![
+ left("geomean"),
+ right2(geo_hit[0].powf(1.0 / n)),
+ right2(geo_hit[1].powf(1.0 / n)),
+ right2(geo_hit[2].powf(1.0 / n)),
+ right2(geo_hit[3].powf(1.0 / n)),
+ right2(geo_miss[0].powf(1.0 / n)),
+ right2(geo_miss[1].powf(1.0 / n)),
+ right2(geo_miss[2].powf(1.0 / n)),
+ right2(geo_miss[3].powf(1.0 / n)),
+ ]));
+ table.add_row(Row::new(vec![
+ left("wins (hit×miss geomean)"),
+ left(&wins[0].to_string()),
+ left(&wins[1].to_string()),
+ left(&wins[2].to_string()),
+ ]));
+ table.add_row(Row::new(vec![
+ left("auto picks"),
+ left(&auto_picks[0].to_string()),
+ left(&auto_picks[1].to_string()),
+ left(&auto_picks[2].to_string()),
+ ]));
+ table.add_row(Row::new(vec![left(
+ format!("auto == per-cell best: {auto_optimal}/{cells}").as_str(),
+ )]));
+ table.add_row(Row::new(vec![left(
+ format!("auto within 5% of best: {auto_within5}/{cells}").as_str(),
+ )]));
+
+ table.printstd();
+}
diff --git a/mingling_macros/src/systems/dispatch_auto.rs b/mingling_macros/src/systems/dispatch_auto.rs
index 54784e2..4cbb6fd 100644
--- a/mingling_macros/src/systems/dispatch_auto.rs
+++ b/mingling_macros/src/systems/dispatch_auto.rs
@@ -1,4 +1,3 @@
-// Doc Not Optimize
//! Auto dispatch-strategy selection (no dispatch feature enabled).
//!
//! Picks the matching strategy at macro-expansion time from the normalized
diff --git a/mingling_macros/src/systems/dispatch_list_gen.rs b/mingling_macros/src/systems/dispatch_list_gen.rs
index 52b0e86..19c487c 100644
--- a/mingling_macros/src/systems/dispatch_list_gen.rs
+++ b/mingling_macros/src/systems/dispatch_list_gen.rs
@@ -1,4 +1,3 @@
-// Doc Not Optimize
use std::cmp::Reverse;
use proc_macro2::TokenStream;
diff --git a/mingling_macros/src/systems/dispatch_phf_gen.rs b/mingling_macros/src/systems/dispatch_phf_gen.rs
index 97210e2..a85a410 100644
--- a/mingling_macros/src/systems/dispatch_phf_gen.rs
+++ b/mingling_macros/src/systems/dispatch_phf_gen.rs
@@ -1,4 +1,3 @@
-// Doc Not Optimize
//! Perfect-hash dispatch generator (`dispatch_phf` feature).
//!
//! Generates a `dispatch_args()` body using a **CHD minimal perfect hash**
diff --git a/mingling_macros/src/systems/dispatch_tree_gen.rs b/mingling_macros/src/systems/dispatch_tree_gen.rs
index 08fc78b..30e04a8 100644
--- a/mingling_macros/src/systems/dispatch_tree_gen.rs
+++ b/mingling_macros/src/systems/dispatch_tree_gen.rs
@@ -1,4 +1,3 @@
-// Doc Not Optimize
//! Char-level trie dispatch generator (`dispatch_tree` feature).
//!
//! Builds a hardcoded match tree: at each depth, group nodes by character.