Routing Guide: Matchit vs RegEx

Choosing the right routing strategy can make a significant difference in your FastEdge application's performance. This guide benchmarks three approaches on WASM.

Approach 1: matchit

matchit is a Rust route-recognition library that uses a radix tree. It supports path parameters and is optimized for lookup speed.

use matchit::Router;

let mut router = Router::new();
router.insert("/blog/:slug", BlogPost).unwrap();
router.insert("/apps/:name", AppDetail).unwrap();

if let Ok(matched) = router.at("/blog/getting-started") {
    // matched.params.get("slug") == "getting-started"
}

Approach 2: RegEx

Using regex crate for pattern matching. More flexible but slower for high-throughput workloads.

use regex::Regex;

let blog_re = Regex::new(r"^/blog/(?P[^/]+)$").unwrap();
if let Some(caps) = blog_re.captures(path) {
    // caps["slug"] access
}

Approach 3: Hand-rolled match

The approach used on this very site — simple match on path strings. Zero allocation, zero dependencies, maximal performance for small route tables.

Bottom line: For fewer than 20 routes, a hand-rolled match is fastest and simplest. For dynamic routes with path parameters, matchit is the sweet spot.