Skip to content

perf(mux): the Mux::timeouts and Context::backend_streams tables still allocate per session #1613

Closed

Description

@FlorentinDUBOIS

Problem

#1612 cut the allocations of a mux session's setup and left two sites it named as a follow-up: the hashbrown tables of Mux::timeouts and Context::backend_streams. Both are created per session and allocate a control/bucket array on their first insert, so a plain H1 request (one request per connection) still pays heap allocations for two tables that, in the common case, hold one frontend handle, one backend handle and one backend entry listing a single stream.

  • Mux::timeouts: HashMap<Token, TimeoutContainer> is built with HashMap::from([(frontend_token, container)]) in lib/src/http.rs (session creation and the PROXY-protocol upgrade) and lib/src/https.rs (TLS handshake upgrade). Its keys are the frontend token, always present for the session's lifetime, plus one token per live backend connection.
  • Context::backend_streams: HashMap<Token, Vec<GlobalStreamId>> is the backend-token → linked-streams reverse index. A session almost always holds one backend connection, and an H1 backend carries one stream at a time.

Proposal

  • Mux::timeouts: keep the frontend handle in a named field (its key is fixed for the session) and the backend handles in an inline-first container with an overflow map, the same shape as BackendConnections in perf(mux): cut the allocations of a session's setup #1612.
  • Context::backend_streams: an inline slot for the first backend token with a fallback to the table for multi-backend sessions.
  • Same semantics, including any observable iteration order; no new dependency; no refactor beyond these two sites.

Measure per site with crate::test_allocations and end to end (H1, H2, H2 multiplexed) with an LD_PRELOAD malloc counter, before and after.

Activity

  1. added a commit that references this issue on Sep 27, 2026
    a078550
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