Repository navigation
cw-out: avoid O(n^2) work while buffering paused output - #22896
Closed
MegaManSec wants to merge 3 commits into
Closed
MegaManSec wants to merge 3 commits into
MegaManSec wants to merge 3 commits into
Conversation
When a header callback returns CURL_WRITEFUNC_PAUSE, cw_out_do_write downgraded the resulting CURLE_AGAIN to CURLE_OK, so the HTTP/2 layer kept feeding it every remaining decoded header field in the current HPACK block instead of stopping. on_header() now returns NGHTTP2_ERR_PAUSE while paused, nghttp2's documented mechanism to halt decoding mid-block, and the pending-input loop breaks on pause too. Separately, the pause buffer's cw_out_buf chain was a stack replayed via recursive tail-hunting, and its buffered length was recomputed by a full list walk on every append: both O(n^2) over the chain. Track a tail pointer and a running length instead.
Contributor
|
As I understand it, |
Contributor
Author
|
Right, let's get rid of that and just keep this pr focused on one thing (the perf bump attempt). Will chahge |
Contributor
Author
|
Updated as discussed: removed the HTTP/2 pause behavior changes. This PR now focuses only on the cw-out paused-buffer performance improvement. |
There was a problem hiding this comment.
🟢 Approval recommended
The queue invariants, byte accounting, cleanup, and output ordering remain correct.
Pull request overview
Optimizes paused-output buffering while preserving FIFO callback behavior.
Changes:
- Adds constant-time tail insertion and buffered-length tracking.
- Replaces recursive reverse-list flushing with iterative oldest-first flushing.
File summaries
| File | Description |
|---|---|
lib/cw-out.c |
Optimizes buffer append, size accounting, cleanup, and flushing. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improves paused-output buffer performance without changing protocol behavior.
The buffer chain now keeps a tail pointer, so appending does not repeatedly walk the list, and tracks the total buffered length instead of rescanning every buffer on each append. Flushing proceeds from the oldest buffer iteratively.
This reduces buffering many paused writes from quadratic list/replay bookkeeping to linear work.