http: use intrusive lists in ConnectionsList - #65296
Open
mcollina wants to merge 1 commit into
Open
Conversation
Collaborator
|
Review requested:
|
Every HTTP message was performing multiple erase and insert operations on two std::set instances ordered by a mutating key, showing up as ~2% of CPU cycles in a hello-world server profile due to red-black tree rebalancing and node allocations. Replace both sets with intrusive doubly-linked lists. Membership in the list of all connections no longer changes per message, and updating the active connections list is now O(1) with no allocations. Appending to the tail keeps the active list ordered by last_message_start_ because uv_hrtime() is monotonic.
mcollina
force-pushed
the
http-connectionslist-intrusive
branch
from
August 15, 2026 04:07
e7c6580 to
41044a2
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65296 +/- ##
=========================================
Coverage 90.30% 90.31%
=========================================
Files 759 751 -8
Lines 248294 250241 +1947
Branches 46860 47294 +434
=========================================
+ Hits 224220 226002 +1782
- Misses 15516 15618 +102
- Partials 8558 8621 +63
🚀 New features to boost your workflow:
|
ronag
approved these changes
Aug 15, 2026
ronag
reviewed
Aug 15, 2026
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.
Every HTTP message was performing multiple erase and insert operations on the two
std::setinstances inConnectionsList, which are ordered by a key (last_message_start_) that mutates on every message. In a hello-world server profile this showed up as ~2.2% of total CPU cycles spent in red-black tree rebalancing plus tree-node allocations, all on the per-request hot path.This PR replaces both sets with intrusive doubly-linked lists:
Remove()is idempotent and the destructor unlinks automatically, which also removes the old "Pop from the lists BEFORE resetting last_message_start_" footgun.on_message_begin/on_message_completeis gone entirely.last_message_start_becauseuv_hrtime()is monotonic, soexpired()semantics are unchanged. The arrays returned byall()/idle()/active()are now in insertion order instead of comparator order; none of their consumers depend on ordering.Benchmark results (Linux, i7-7700, server and benchmarker pinned to separate cores):
A separate interleaved wrk A/B (hello-world server,
-t2 -c50, 5 alternating pairs) shows +4.9% (26,599 → 27,914 req/s), with the patched binary winning every pair. A perf profile of the patched binary confirms the_Rb_treesymbols are gone and malloc traffic in the parser path is roughly halved.This PR was prepared with the help of AI assistance.