Skip to content

perf(router): avoid path-param HashMap allocation for static routes #106

Description

@ZhuchkaTriplesix

Context

  • match_route_compiled in src/state.rs always allocates HashMap<String, String> for path params, even when the route has no :param segments.

Problem

Static routes (the majority in many APIs) pay for an empty HashMap allocation on every request.

Proposed change

  • Return (idx, Option<PathParams>) or use a static empty sentinel / SmallVec for 0–2 params.
  • Avoid HashMap::new() when matchit params iterator is empty.

Files

  • src/state.rs, src/dispatch.rs, call sites in WebSocket matching

Acceptance criteria

  • Routing behaviour unchanged for parameterized and static routes.
  • Unit tests for static and dynamic paths.
  • Optional microbench shows fewer allocations per match.

Expected low-level impact

Fewer heap allocations on every matched static route.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions