Avoid quadratic copying when sending large HTTP/2 request bodies - #1127
Conversation
|
Docs preview: https://2c961427-httpx2-docs.pydantic.workers.dev |
Merging this PR will improve performance by ×290
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Memory | test_bench_http2_send_large_body |
16,375.9 KB | 55.9 KB | ×290 |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing http2-offset-send (e891529) with main (d6d7ec3)
Footnotes
-
7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4dcdf3457d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Closes #1039.
_send_stream_datarebuilt the remaining body tail as a freshbytesobject on every frame, copying ~n²/2kbytes for annbyte body sent inkbyte frames. This replaces it with an offset-based loop so each byte is sliced once.Benchmark sending a single
bytesbody throughHTTP2Connectionover aMockStream(16 KiB frames):AI Disclaimer
This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.