Making WAF ML models go brrr: saving decades of processing time
Jul 25, 2024Alex Bocharov

Summary
This post details performance optimizations for Cloudflare's WAF ML models, achieving a 5.5x speedup (82% reduction in execution time) by optimizing the feature extraction process. The primary optimization involved replacing `std::collections::HashMap` lookups with the Aho-Corasick algorithm (specifically using `AhoCorasickKind::DFA`) for ngram processing, reducing lookup time and improving cache efficiency. Additionally, the post mentions optimizations for `regex::regex::bytes::Regex::replace_all` and discusses the overall system design of the WAF Attack Score, including normalization, feature extraction, and model inference.
More from the Artificial Intelligence Integration & Impact trail
- Introducing Clef-omni with full multimodality, plus a faster Clef and a cheaper Clef-flash
- Introducing Web Search API via AI Gateway
- Introducing Clef: our open-source decision models, and new RL fine-tuning platform
- One year later: Sovereign AI and the fight for choice
- AI Search is now generally available