Skip to content

perf(router): route_from_request still allocates for original_authority and the trie path #1589

Closed

Description

@FlorentinDUBOIS

Context

#1584 measured three heap allocations left per routed request inside Router::route_from_request (lib/src/protocol/mux/router.rs). Two of them need no public API change:

  1. route_from_request copies the request authority (host.to_owned()) into HttpContext::original_authority on every request. The only reader is the X-Forwarded-Host injection of apply_request_rewrites_and_headers, which fires only when the frontend rewrites the host. HttpContext::authority is never mutated by routing, so the pre-rewrite value is still there when that header is built; the field's own documentation already says it is None when no host rewrite happened.
  2. Router::lookup (lib/src/router/mod.rs) hands the trie a Vec::with_capacity(16) to record the wildcard/regex segments it matched, so every tree lookup allocates, including a literal host that records nothing.

Proposal

  • Populate original_authority only when a host rewrite applies, from HttpContext::authority, so a request without a host rewrite copies nothing.
  • Record the trie segments into a fixed 16-slot stack buffer that spills to a Vec only past 16 non-literal segments; TrieMatches and TrieNode::lookup_with_path stay as they are.
  • Pin both with the crate's counting test allocator.

Out of scope: the cluster id cloned out of the route table (ClusterId = String in sozu-command-lib) and SessionManager::track_cluster_connection.

Activity

  1. added a commit that references this issue on Sep 26, 2026
    bbceca8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions