Repository navigation
refactor: Extract shared event queue for transport and http3 - #3905
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3905 +/- ##
==========================================
- Coverage 97.05% 96.75% -0.30%
==========================================
Files 115 118 +3
Lines 41097 39769 -1328
Branches 41097 39769 -1328
==========================================
- Hits 39886 38479 -1407
- Misses 1194 1265 +71
- Partials 17 25 +8
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Is there maybe even an external crate we could use? |
There was a problem hiding this comment.
Pull request overview
Extracts shared event-queue behavior into neqo-common while preserving transport deduplication and HTTP/3 duplicate handling.
Changes:
- Adds reusable
event::Queue<T>with FIFO, deduplication, removal, and shared-clone operations. - Migrates transport and HTTP/3 event producers to the shared queue.
- Adds unit tests covering queue behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
neqo-common/src/event.rs |
Implements and tests the shared event queue. |
neqo-transport/src/events.rs |
Migrates transport events while preserving deduplication. |
neqo-http3/src/client_events.rs |
Migrates client event handling. |
neqo-http3/src/server_events.rs |
Migrates server event handling. |
neqo-http3/src/server_connection_events.rs |
Migrates per-connection server events. |
neqo-http3/src/connection_client.rs |
Uses the renamed client event append method. |
neqo-http3/src/connect_udp.rs |
Updates Connect-UDP event production. |
neqo-http3/src/webtransport.rs |
Updates WebTransport event production. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
What would be the benefit of an external crate @larseggert? |
There was a problem hiding this comment.
Reviewed the refactor end-to-end against the old insert implementations; I agree with the "no behavior change" claim:
- Transport's old
insertspecial-casedSendStreamStopSending/RecvStreamReset(dedup bystream_id, ignoringapp_error) and fell back toq.contains(&event)otherwise. Moving the special cases topush_unique_byat the two call sites and usingpush_uniqueeverywhere else is equivalent, and the two paths that deliberately bypassed dedup (add_datagram,datagram_outcome, which calledpush_backdirectly) correctly map topush. - The clear-then-insert paths (
client_0rtt_rejected,connection_state_change,scone_updated) are unaffected, since the queue is empty of matching events by the timepush_uniqueruns. - http3's
insertnever deduped, sopusheverywhere there is right. Http3ServerEvents::events():replace(VecDeque::new())→RefCell::take()is the same thing.- The manual
Default/Cloneimpls onQueue<T>(rather than derives) are the right call — derives would spuriously addT: Default/T: Clonebounds and breakConnectionEvents::default()/.clone().
Existing dedup coverage in events::tests::event_culling (differing app_error on reset/stop-sending) still exercises the moved logic, and the new Queue unit tests are a good addition.
A few PR-wide notes:
Re: @larseggert's "is there maybe even an external crate we could use?" — I don't think one is warranted here. This is ~60 lines wrapping Rc<RefCell<VecDeque<T>>>, and the value is entirely in the push/push_unique/push_unique_by trio, which is neqo-specific policy rather than a general data structure. Any crate offering a shared FIFO would still leave the dedup logic here, so it would add a dependency without removing the interesting code.
Performance. push_unique is a linear scan on every event push, so recv_stream_readable/send_stream_writable are O(n²) in the number of queued events. That's pre-existing, not introduced here, and the CodSpeed regression flagged on this PR is range_tracker::coalesce_acked_from_zero — untouched by this change, so noise. Worth noting that centralizing the queue makes a future fix (e.g. a side HashSet of queued keys) a single-file change; a micro-benchmark for Queue::push_unique at realistic stream counts would make that measurable.
Public API. neqo_common::event::Queue is new public surface, and Http3ClientEvents::insert → push is a rename on an existing public method (see inline comment). Neither is used by mozilla-central as far as I can tell, but the rename is worth a line in the changelog.
Core reduction. But I made this comment before looking at the actual PR, which is not that large :-) |
20b190d to
6af2fef
Compare
The event queues in `neqo-transport` and `neqo-http3` each wrapped their own `Rc<RefCell<VecDeque<_>>>` and both named the append method `insert`, though transport's dropped duplicates and http3's did not. Move the wrapper into `neqo-common` as `event::Queue<T>`, offering `push` to append and `push_unique` to append only if no equal event is queued. No behavior change.
6af2fef to
43b7414
Compare
`Queue` reads as a collection, so it should spell emptiness the way the standard collections do. Only the four wrappers delegating to it change; the `Provider` trait and its `has_events` stay as they are.
martinthomson
left a comment
There was a problem hiding this comment.
The design looks sound, but here are a few things to chew on.
Most transport emitters cannot queue a duplicate, so the scan that `push_unique` does is dead work: `new_stream` sees each stream ID once, `client_resumption_token` gets a fresh token each call, `authentication_needed` is guarded by `was_authentication_pending`, and `client_0rtt_rejected` pushes onto a queue it has just cleared. `send_stream_complete` now drops any earlier `SendStreamComplete` in the scan it already runs, so it needs only one pass. `path_migrated` changes behavior: migrating away from a path and back queued the same event twice, and the second was silently dropped. Alias the import as `EventQueue` so the type reads clearly at use sites.
Head branch was pushed to by a user without write access
Performance profiles for profiler.firefox.comBenchmarks (14)
|
Benchmark resultsNo significant performance differences relative to 5257f92. All resultsstreams/walltime/1-streams/each-1000-bytes: No change in performance detected. time: [541.08 µs 542.89 µs 545.02 µs]
thrpt: [1.7498 MiB/s 1.7567 MiB/s 1.7625 MiB/s]
change:
time: [-0.6382% -0.1318% +0.3680] (p = 0.62 > 0.05)
thrpt: [-0.3666% +0.1319% +0.6423]
No change in performance detected.
Found 12 outliers among 100 measurements (12.00%)
1 (1.00%) high mild
11 (11.00%) high severestreams/walltime/1000-streams/each-1-bytes: Change within noise threshold. time: [10.517 ms 10.530 ms 10.544 ms]
thrpt: [92.618 KiB/s 92.740 KiB/s 92.860 KiB/s]
change:
time: [-2.1431% -1.9643% -1.7862] (p = 0.00 < 0.05)
thrpt: [+1.8187% +2.0037% +2.1901]
Change within noise threshold.streams/walltime/1000-streams/each-1000-bytes: Change within noise threshold. time: [30.422 ms 30.452 ms 30.483 ms]
thrpt: [31.286 MiB/s 31.317 MiB/s 31.349 MiB/s]
change:
time: [-2.1065% -1.9659% -1.8139] (p = 0.00 < 0.05)
thrpt: [+1.8474% +2.0053% +2.1518]
Change within noise threshold.streams-flow-controlled/walltime/1-streams/each-4194304-bytes: Change within noise threshold. time: [26.061 ms 26.093 ms 26.126 ms]
thrpt: [153.10 MiB/s 153.30 MiB/s 153.49 MiB/s]
change:
time: [-0.7562% -0.5774% -0.4062] (p = 0.00 < 0.05)
thrpt: [+0.4078% +0.5807% +0.7619]
Change within noise threshold.streams-flow-controlled/walltime/10-streams/each-1048576-bytes: Change within noise threshold. time: [71.594 ms 71.671 ms 71.748 ms]
thrpt: [139.38 MiB/s 139.53 MiB/s 139.68 MiB/s]
change:
time: [-0.7582% -0.6060% -0.4603] (p = 0.00 < 0.05)
thrpt: [+0.4624% +0.6097% +0.7640]
Change within noise threshold.transfer/walltime/pacing-false/varying-seeds: Change within noise threshold. time: [17.822 ms 17.832 ms 17.842 ms]
thrpt: [224.19 MiB/s 224.31 MiB/s 224.44 MiB/s]
change:
time: [-1.5776% -1.4982% -1.4204] (p = 0.00 < 0.05)
thrpt: [+1.4409% +1.5210% +1.6029]
Change within noise threshold.transfer/walltime/pacing-true/varying-seeds: Change within noise threshold. time: [18.289 ms 18.300 ms 18.311 ms]
thrpt: [218.45 MiB/s 218.58 MiB/s 218.71 MiB/s]
change:
time: [-1.8754% -1.8006% -1.7205] (p = 0.00 < 0.05)
thrpt: [+1.7507% +1.8336% +1.9112]
Change within noise threshold.transfer/walltime/pacing-false/same-seed: No change in performance detected. time: [17.866 ms 17.877 ms 17.888 ms]
thrpt: [223.61 MiB/s 223.75 MiB/s 223.89 MiB/s]
change:
time: [-0.0153% +0.0775% +0.1673] (p = 0.10 > 0.05)
thrpt: [-0.1670% -0.0775% +0.0153]
No change in performance detected.
Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) high mildtransfer/walltime/pacing-true/same-seed: Change within noise threshold. time: [18.378 ms 18.392 ms 18.406 ms]
thrpt: [217.32 MiB/s 217.49 MiB/s 217.65 MiB/s]
change:
time: [+1.3144% +1.4100% +1.5075] (p = 0.00 < 0.05)
thrpt: [-1.4851% -1.3904% -1.2973]
Change within noise threshold.
Found 2 outliers among 100 measurements (2.00%)
2 (2.00%) high mildDownload data for |
Failed Interop TestsQUIC Interop Runner, client vs. server, differences relative to
All resultsSucceeded Interop TestsQUIC Interop Runner, client vs. server neqo-pr as client
neqo-pr as server
Unsupported Interop TestsQUIC Interop Runner, client vs. server neqo-pr as client
neqo-pr as server
|
Client/server transfer resultsPerformance differences relative to 5257f92. Transfer of 33554432 bytes over loopback, min. 100 runs. All unit-less numbers are in milliseconds.
Table above only shows statistically significant changes. See all results below. All resultsTransfer of 33554432 bytes over loopback, min. 100 runs. All unit-less numbers are in milliseconds.
Download data for |
The event queues in
neqo-transportandneqo-http3each wrapped their ownRc<RefCell<VecDeque<_>>>and both named the append methodinsert, though transport's dropped duplicates and http3's did not.Move the wrapper into
neqo-commonasevent::Queue<T>, offeringpushto append andpush_uniqueto append only if no equal event is queued. No behavior change.Noticed while working on #3859.