From 5678e0ba37ce2c5c8161f0d48505e7993967e30c Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 20 Aug 2026 03:38:10 +0800 Subject: feat: add dispatch strategy features with auto-selection and benchmark support Add `dispatch_linear`, `dispatch_tree`, and `dispatch_phf` as mutually exclusive features for selecting the command dispatch strategy. When no strategy feature is enabled, an auto-selection heuristic picks the optimal strategy based on command table characteristics (size, name length, nesting depth). Add the `bench_support` feature to compile all three generators for the benchmark harness, and introduce `bench_cell!` to generate benchmark cells comparing strategies. The PHF generator uses a CHD minimal perfect hash for O(1) lookup independent of table size, while the trie generator was refactored to use a shared fallback method, keeping code size linear in table size. --- mingling/Cargo.toml | 5 +++++ mingling/src/features.rs | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'mingling') diff --git a/mingling/Cargo.toml b/mingling/Cargo.toml index 7c7993b..92cca39 100644 --- a/mingling/Cargo.toml +++ b/mingling/Cargo.toml @@ -54,7 +54,12 @@ docs_rs = [] # Features clap = ["mingling_core/clap", "mingling_macros/clap"] + +# Dispatch strategy (mutually exclusive; none = auto, currently linear) +dispatch_linear = ["mingling_macros/dispatch_linear"] dispatch_tree = ["mingling_macros/dispatch_tree"] +dispatch_phf = ["mingling_macros/dispatch_phf"] + repl = ["mingling_core/repl", "mingling_macros/repl"] comp = ["mingling_core/comp", "mingling_macros/comp"] picker = ["mingling_core/picker", "dep:arg-picker", "arg-picker/mingling_support"] diff --git a/mingling/src/features.rs b/mingling/src/features.rs index 8a3ce75..3d9a382 100644 --- a/mingling/src/features.rs +++ b/mingling/src/features.rs @@ -86,6 +86,28 @@ pub const MINGLING_DEFAULT: bool = false; #[cfg(feature = "default")] #[allow(unused)] pub const MINGLING_DEFAULT: bool = true; +/// Whether the `dispatch_linear` feature is enabled +/// Current: `disabled` +#[cfg(not(feature = "dispatch_linear"))] +#[allow(unused)] +pub const MINGLING_DISPATCH_LINEAR: bool = false; + +/// Whether the `dispatch_linear` feature is enabled +/// Current: `enabled` +#[cfg(feature = "dispatch_linear")] +#[allow(unused)] +pub const MINGLING_DISPATCH_LINEAR: bool = true; +/// Whether the `dispatch_phf` feature is enabled +/// Current: `disabled` +#[cfg(not(feature = "dispatch_phf"))] +#[allow(unused)] +pub const MINGLING_DISPATCH_PHF: bool = false; + +/// Whether the `dispatch_phf` feature is enabled +/// Current: `enabled` +#[cfg(feature = "dispatch_phf")] +#[allow(unused)] +pub const MINGLING_DISPATCH_PHF: bool = true; /// Whether the `dispatch_tree` feature is enabled /// Current: `disabled` #[cfg(not(feature = "dispatch_tree"))] -- cgit