Skip to content

Small optimizations#27

Draft
KA-ROM wants to merge 17 commits into
mainfrom
perf/cheap-allocs
Draft

Small optimizations#27
KA-ROM wants to merge 17 commits into
mainfrom
perf/cheap-allocs

Conversation

@KA-ROM
Copy link
Copy Markdown

@KA-ROM KA-ROM commented Jun 5, 2026

Summary

Six small, self-contained optimizations on the engine_* hot path, each removing a per-request memory allocation or a redundant lookup. No behavior changes.

What this removes from the hot path

  • No heap allocation per header check: is_hop_by_hop_header used to allocate a lowercased String for every comparison; it now matches HeaderName constants directly, so the allocation is gone.
  • ~10 fewer hashmap lookups per request: in-flight Gauge/Counter handles were resolved via get_or_create on every request; they're now resolved once and cached on ProxyHttp.
  • No metric lookup on the user-agent path: the handle is cached per worker in an scc::HashMap<String, Counter>, so the warm path is a plain &str read instead of a metric-family lookup plus allocation.
  • connection_info() called once instead of 5×: bound a single time per request and reused.
  • No per-header revalidation when appending: headers_mut().append(...) skips reparsing each header name through the builder.
  • No re-parse on response forwarding: dropped HeaderName::from_str. Backend header names are already valid, so the parse and its error path were dead weight.

@KA-ROM KA-ROM marked this pull request as draft June 5, 2026 13:10
@KA-ROM KA-ROM changed the title Perf/cheap allocs Small optimizations Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant