Skip to content

Perf: reduce per-exchange allocations on HTTP/1.1 hot path#631

Merged
haga-rak merged 3 commits into
mainfrom
perf/gate-live-edit-scan
Apr 16, 2026
Merged

Perf: reduce per-exchange allocations on HTTP/1.1 hot path#631
haga-rak merged 3 commits into
mainfrom
perf/gate-live-edit-scan

Conversation

@haga-rak
Copy link
Copy Markdown
Owner

Summary

Three small allocation cuts on the HTTP/1.1 MITM path:

  • Gate the per-exchange x-fluxzy-live-edit header scan behind the FluxzyDesktopVersion env var (exposed as FluxzySharedSetting.LiveEditEnabled). Standalone fluxzy no longer walks every request's headers looking for a desktop-only debug flag.
  • ExchangeScope now uses two inline char[]? slots plus a lazy overflow list, renting directly from ArrayPool<char>.Shared. Drops the unconditional List<IDisposable> allocation and the IMemoryOwner wrapper that MemoryPool<char>.Shared.Rent returns per header buffer.
  • Added TryGetFirstHeader, TryGetLastHeader, HasHeaderValueEqualsAny, and HasHeaderValueContains helpers on Header that iterate the backing List<HeaderField> via its struct enumerator. Rewrote RequestHeader.InitSettings, the ResponseHeader constructors, and ReadKeepAliveSettings to use them, removing the yield-return iterator allocations from each First/Any/LastOrDefault call.

Targeting the UseProxy=True, ServeH2=False, ResponseBodyLength=0 row in ProxyThroughputBenchmark (~7.7 µs, ~12.6 KB/op).

Skips the per-exchange x-fluxzy-live-edit header scan when not running
under Fluxzy Desktop, removing a LINQ allocation and full header walk
from the HTTP/1.1 hot path.
Replace List<IDisposable> + MemoryPool<char>.Shared with two inline char[]
slots backed by ArrayPool<char>.Shared (plus lazy overflow List). Saves a
List allocation per scope and the IMemoryOwner wrapper per rent on the
HTTP/1.1 hot path.
RequestHeader.InitSettings and ResponseHeader's constructor plus
ReadKeepAliveSettings used First/Any/LastOrDefault on the indexer, each
allocating a yield-return iterator per call. Added TryGetFirstHeader,
TryGetLastHeader, HasHeaderValueEqualsAny, and HasHeaderValueContains
helpers on Header that iterate the backing List directly with its struct
enumerator, and rewrote the callers accordingly.
@haga-rak haga-rak merged commit 7715549 into main Apr 16, 2026
2 checks passed
@haga-rak haga-rak deleted the perf/gate-live-edit-scan branch May 7, 2026 21:56
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