Skip to content

serialize: reduce header-path allocations safely - #264

Merged
anmonteiro merged 1 commit into
masterfrom
perf/header-encoding-allocs
Mar 9, 2026
Merged

serialize: reduce header-path allocations safely#264
anmonteiro merged 1 commit into
masterfrom
perf/header-encoding-allocs

Conversation

@anmonteiro

Copy link
Copy Markdown
Owner

Summary

  • avoid List.rev allocation on hot header paths by iterating headers in HPACK/wire order (Headers.iter_hpack)
  • use a reusable header scratch encoder in Serialize.Writer instead of allocating a fresh Faraday for every request/response/trailer header block
  • preserve correctness for queued writes by copying header iovecs into the main writer for HEADERS/PUSH_PROMISE/CONTINUATION payloads (avoids shared-buffer aliasing)
  • add a TODO documenting follow-up work to move to pooled header buffers for zero-copy safety

Why

This targets two perf findings:

  • repeated header-list reversals in serialization/validation
  • per-message Faraday allocations in header encoding

The initial shared-scratch zero-copy attempt regressed an existing test (headers blocks don't share buffers) due buffer aliasing. This PR keeps the optimization while maintaining correctness.

Validation

  • dune runtest --no-buffer

@anmonteiro
anmonteiro force-pushed the perf/header-encoding-allocs branch from 8418083 to 782d7a0 Compare March 9, 2026 03:40
@anmonteiro
anmonteiro force-pushed the perf/header-encoding-allocs branch from 782d7a0 to 0abbd0e Compare March 9, 2026 03:42
@anmonteiro
anmonteiro merged commit a5449e5 into master Mar 9, 2026
6 checks passed
@anmonteiro
anmonteiro deleted the perf/header-encoding-allocs branch March 9, 2026 03:52
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