GET //Maravel-Ecosystem/ Maravel-Framework 10.67.0 brings a new, faster and safer Router via Maravel 10.52.48
root @maravel-ecosystem:~/Development / Maravel-Framework 10.67.0 brings a new, faster and safer Router via Maravel 10.52.48

Maravel-Framework 10.67.0 brings a new, faster and safer Router via Maravel 10.52.48

Maravel-Framework 10.67.0 brings a new, faster and safer Router via Maravel 10.52.48.

To keep it as fast as possible, avoid complex routes like:

  • Greedy Wildcards: /{any:.*}
  • Inline Parameters: /export-{date}.csv
  • Adjacent Parameters: /{code}{number}

This is NOT a complex route:

$r->addRoute('GET', '/user/{id:\d+}', 'handler');

A new match method was also introduced:

$router->match(['GET', 'POST'], $uri, $callback);

The Hello World bench is not touched by this change because it uses a static route:

Press enter or click to view image in full size

The documentation has been updated.

The New Maravel Trie Router Summary

This is a major architectural overhaul of the Maravel Micro-Framework's routing engine. The framework eliminated the "Regex Tax" inherent in traditional routers like FastRoute by shifting from a linear regex search to a native, tiered discovery model.

The 3-Tiered Architecture:

1. The Hash Shield (Static O(1)): Static routes (like /health) are resolved instantly using a flat PHP Hash Map before the rest of the engine even wakes up (no change here).

2. The Native Trie (Dynamic O(K)): Standard dynamic routes (like /users/{id}) are placed in a pre-compiled Prefix Tree (Trie). Using PHP’s native strtok, the router walks the tree segment-by-segment. Routing time is strictly tied to the length of the URL, completely decoupled from the total number of routes.

3. The Hybrid Fallback: Complex routes (greedy wildcards, inline variables) are isolated in a complexRoutes queue and delegated to a scoped FastRoute instance. This limits regex usage to only the 5% of edge cases that actually need it.

Key Breakthroughs & Security:

The 404 Firewall: Traditional routers are slowest on 404s because they check every regex group before failing. The Maravel Trie fails instantly at the first invalid URL segment (e.g., a bot scanning for /wp-admin), acting as a highly efficient shield against DDoS and bot traffic (the complex routes will still be executed).

Native Trailing Slashes: The strtok implementation naturally resolves the trailing slash problem (/api equals /api/) for standard routes without extra middleware.

Security Through Omission: The framework dropped support for "405 Method Not Allowed" in favor of returning 404s. This stops the router from exhaustively searching for other HTTP verbs after a path mismatch, reclaiming CPU cycles.

Conclusion:

By restricting FastRoute to just parsing and handling a small subset of complex anomalies, Maravel leverages OpCache-friendly nested arrays to achieve massive scalability. The framework no longer relies on on-the-fly cached files, avoiding disk-write concurrency issues and ensuring CPU cycles are spent on business logic, not infrastructure.