Skip to content

perf: avoid copying DATA payloads in parser - #270

Open
anmonteiro wants to merge 1 commit into
masterfrom
perf/data-frame-payload-view
Open

perf: avoid copying DATA payloads in parser#270
anmonteiro wants to merge 1 commit into
masterfrom
perf/data-frame-payload-view

Conversation

@anmonteiro

Copy link
Copy Markdown
Owner

Summary

Avoid allocating a fresh bigstring for every parsed HTTP/2 DATA frame.

Instead of using Angstrom.take_bigstring for DATA payloads, carry a (buffer, off, len) payload view through Frame.Data and write directly into the Body.Reader buffer.

Why

Angstrom.take_bigstring copies.

On the request/response body hot path, that meant one intermediate bigstring allocation per DATA frame before the body bytes were copied into the reader-side Faraday buffer.

This change removes that intermediate allocation while keeping header-block parsing unchanged.

Validation

  • dune build --display=short @runtest-test_h2 @runtest-test_h2_client @runtest-test_h2_server
  • local 1.5 GiB upload benchmark against the local Eio benchmark server

Observed benchmark delta on the local upload benchmark:

  • before: 4.21s (364.40 MiB/s)
  • after: 3.70s (414.99 MiB/s)

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