Repository navigation
perf(endpoint): keep the deadlines in a heap for the timer path - #15
Open
pylaterreur wants to merge 2 commits into
Open
pylaterreur wants to merge 2 commits into
pylaterreur wants to merge 2 commits into
Conversation
poll_timeout computed every connection's deadline at each call and handle_timeout ran every connection's timer pass, so an event loop paid O(N) per wakeup whatever was due (issue mp0rta#12). Each connection now caches its deadline (what poll_timeout computed for it, unchanged), and a min-heap of (deadline, handle) with lazy deletion orders the cached ones. Every endpoint call that reaches a connection marks it: a packet for it, a path call, connection(h) (which hands out &mut Connection), a turn of poll_transmit and a handle_timeout pass. A marked connection's entry leaves the heap once it reaches the top, and its deadline is cached again once poll_transmit has nothing left to send or handle_timeout runs; until then poll_timeout computes it afresh, so it returns what the full scan returned. handle_timeout processes, in handle order, the connections whose deadline passed and those an endpoint call reached since their last pass (which every connection used to get), and frees only among them. apply_aborts looks only at the connections the application reached. poll_transmit still visits every connection. A turn that sends nothing and leaves nothing for the next turn leaves the connection idle until its wake time (its deadline or a pacing release): the turns until then change nothing, so they need no new deadline. The full scan stays as a test-only oracle (Endpoint::full_scan), and diff_tests runs randomized two-endpoint scenarios both ways and checks that the packets, in order, the events, poll_timeout values, reads and call results are the same. With 2000 idle MPTCP connections handle_timeout processes one connection per call during a bulk transfer instead of 2001 (scale_tests). The rogue-plan tests change the probe scheduler's plan from outside the connection, so they mark it themselves (set_rogue). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN
This branch has not been deployed
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.
Part of #12.
poll_timeoutcomputed every connection's deadline on each call, andhandle_timeoutran every connection's timer pass, so each event-loop wakeup cost O(N).Each connection now caches its deadline: the per-connection minimum that
poll_timeoutcomputed, unchanged. A min-heap of(deadline, handle)with lazy deletion orders the cached deadlines.connection(h), a turn ofpoll_transmit, ahandle_timeoutpass.poll_transmithas nothing left to send orhandle_timeoutruns. Until thenpoll_timeout(still&self) computes it afresh, so it returns exactly what the full scan returned.handle_timeoutprocesses, in handle order, the connections whose deadline passed and those an endpoint call reached since their last pass (which every connection used to get). It frees only among them.poll_transmitstill visits every connection; the ready-set PR handles that.The full scan stays as a test-only oracle (
Endpoint::full_scan), wherepoll_timeoutandhandle_timeoutlook at every connection.diff_tests, the same as in the ready-set PR, checks the same packets in the same order, events,poll_timeoutvalues, reads and call results.Connections processed per
handle_timeoutcall during a bulk transfer next to N idle MPTCP connections (scale_tests): main processes N+1 (2, 11, 101, 501, 2001 for N = 1, 10, 100, 500, 2000); this PR processes 1.0 for every N.At N=1000, callgrind instructions for a whole run (setup plus a 1 MB transfer):
poll_timeouthandle_timeouthandle_packetpoll_transmit's full walk still dominates, so the whole run is only 5% shorter at N=1000. At N=0 it is 0.7% longer. With both PRs the whole run is 96% shorter at N=1000, and within 0.1% of main at N=0.Testing:
cargo test, clippy, fmt, MSRV 1.85, and the fuzz targets.diff_testson 40 small and 400 large scenarios.poll_timeout, any skipped timer pass that would have changed a connection, and any connection freed outside the processed set. No report over the whole test suite and 150 random scenarios.The two PRs are independent; whichever lands second needs a rebase. I have that rebase ready: on top of the ready set, a
handle_timeoutpass also makes its connection ready. With both PRs, the full interop suite passes too.🤖 Generated with Claude Code
https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN