| Mode | Throughput | Latency |
|---|---|---|
| Sequential (cached) | 250+ req/s | <100µs |
| Sequential (cold) | — | ~3–4ms |
| Parallel / Rayon (8-core) | 1,000+ req/s | — |
| Channel D semantic | — | ~31µs |
napi-rs automatically runs evaluations on worker threads — Promise.all gives you free parallelism:
import { Firewall } from "policy-gate";
const firewall = await Firewall.create();
const results = await Promise.all(
["What is the capital of France?", "Write a function", "Hello!"]
.map(p => firewall.evaluate(p))
);Enable the parallel feature for Rayon-based batch evaluation:
# Cargo.toml
firewall-core = { path = "./crates/firewall-core", features = ["parallel"] }use firewall_core::evaluate_batch_parallel;
let results = evaluate_batch_parallel(vec![
"What is the capital of France?".to_string(),
"Write a function".to_string(),
], 0);# All benchmark groups
cargo bench -p firewall-core
# Individual groups
cargo bench -p firewall-core --bench channel_a # FSM + allowlist
cargo bench -p firewall-core --bench channel_b # Rule engine
cargo bench -p firewall-core --bench voter # 1oo2D decision logic
cargo bench -p firewall-core --bench integration # Full pipeline
cargo bench -p firewall-core --bench normalise # Unicode normalizationSee crates/firewall-core/BENCHMARKS.md for detailed results.
For deeper semantic analysis at the cost of 5–20ms latency:
pip install huggingface_hub
python scripts/setup_bert.pyDownloads required model files to models/. Enable in firewall.toml via engine_mode = "bert".