Skip to content
brady@bangasser:~$

The router tree

Omni does not match routes with a linear scan. It compiles them into a ConditionTree: a decision tree whose interior nodes are cheap conditions and whose leaves are route stacks. This is what makes dispatch cost a handful of cycles.

Conditions

A ConditionType partitions a set of routes:

ConditionSplits routes byStatus
SegmentCount(n)number of path segmentsimplemented
Length(n)path string lengthimplemented
Prefix(s)a shared path prefixplanned
Custom(..)a user-provided conditionsupported via trait

Each is a constant-time check (an integer compare, or a prefix test), so walking the tree to a leaf is a short sequence of comparisons rather than a scan over every route.

Passes

A pass inserts a level of conditions into the tree by partitioning the routes at that level. Passes are composable and run in sequence; ordering them well is what shapes an efficient tree.

  • Length partitions by path length.
  • Segcount partitions by segment count.
  • Prefix (planned) partitions by shared prefix.

Custom conditions implement the CustomCondition trait, which also emits the decision code for that condition, so the tree is extensible without changing the core.

Leaves: route stacks

Each leaf is a GenRoute: a path plus, per HTTP method, a stack of the middleware and the handler to run. The generated router walks the condition tree to a leaf, selects the stack for the method, and executes it.