Skip to content

refactor: Extract shared event queue for transport and http3 - #3905

Merged
mxinden merged 3 commits into
mozilla:mainfrom
mxinden-bot:unify-event-insert-dedup
Sep 1, 2026
Merged

mxinden merged 3 commits into
mozilla:mainfrom
mxinden-bot:unify-event-insert-dedup

Conversation

@mxinden

@mxinden mxinden commented Aug 27, 2026

Copy link
Copy Markdown
Member

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.

Noticed while working on #3859.

@codecov

codecov Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.09091% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.75%. Comparing base (80ca01e) to head (7efe298).
⚠️ Report is 12 commits behind head on main.

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     
Flag Coverage Δ
freebsd 94.09% <98.63%> (-0.31%) ⬇️
linux 96.94% <99.09%> (-0.13%) ⬇️
macos 95.02% <98.63%> (-0.18%) ⬇️
windows 95.07% <98.63%> (-0.19%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
neqo-common 99.26% <100.00%> (+0.03%) ⬆️
neqo-http3 95.26% <95.98%> (-0.48%) ⬇️
neqo-qpack 96.88% <ø> (-0.38%) ⬇️
neqo-transport 97.69% <94.28%> (-0.09%) ⬇️
neqo-udp 95.37% <ø> (ø)
mtu 89.13% <ø> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed

codspeed Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 81 untouched benchmarks


Comparing mxinden-bot:unify-event-insert-dedup (7efe298) with main (5257f92)

Open in CodSpeed

@larseggert

Copy link
Copy Markdown
Collaborator

Is there maybe even an external crate we could use?

@mxinden
mxinden marked this pull request as ready for review August 30, 2026 18:01
Copilot AI balanced review requested due to automatic review settings August 30, 2026 18:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mxinden

mxinden commented Aug 30, 2026

Copy link
Copy Markdown
Member Author

Is there maybe even an external crate we could use?

What would be the benefit of an external crate @larseggert?

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the refactor end-to-end against the old insert implementations; I agree with the "no behavior change" claim:

  • Transport's old insert special-cased SendStreamStopSending/RecvStreamReset (dedup by stream_id, ignoring app_error) and fell back to q.contains(&event) otherwise. Moving the special cases to push_unique_by at the two call sites and using push_unique everywhere else is equivalent, and the two paths that deliberately bypassed dedup (add_datagram, datagram_outcome, which called push_back directly) correctly map to push.
  • 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 time push_unique runs.
  • http3's insert never deduped, so push everywhere there is right.
  • Http3ServerEvents::events(): replace(VecDeque::new()) → RefCell::take() is the same thing.
  • The manual Default/Clone impls on Queue<T> (rather than derives) are the right call — derives would spuriously add T: Default/T: Clone bounds and break ConnectionEvents::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.

Comment thread neqo-http3/src/client_events.rs Resolved
Comment thread neqo-common/src/event.rs Resolved
Comment thread neqo-common/src/event.rs Resolved
Comment thread neqo-transport/src/events.rs Resolved
@larseggert

Copy link
Copy Markdown
Collaborator

What would be the benefit of an external crate @larseggert?

Core reduction. But I made this comment before looking at the actual PR, which is not that large :-)

@mxinden-bot
mxinden-bot force-pushed the unify-event-insert-dedup branch from 20b190d to 6af2fef Compare August 31, 2026 08:43
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.
@mxinden-bot
mxinden-bot force-pushed the unify-event-insert-dedup branch from 6af2fef to 43b7414 Compare August 31, 2026 09:19
Comment thread neqo-common/src/event.rs Resolved
`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 martinthomson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The design looks sound, but here are a few things to chew on.

Comment thread neqo-common/src/event.rs Resolved
Comment thread neqo-http3/src/client_events.rs Resolved
Comment thread neqo-transport/src/events.rs Resolved
Comment thread neqo-transport/src/events.rs Resolved
Comment thread neqo-transport/src/events.rs Resolved
Comment thread neqo-transport/src/events.rs Resolved
Comment thread neqo-transport/src/events.rs Resolved
Comment thread neqo-transport/src/events.rs Resolved
Comment thread neqo-transport/src/events.rs Resolved
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.
auto-merge was automatically disabled September 1, 2026 16:37

Head branch was pushed to by a user without write access

@mxinden
mxinden enabled auto-merge September 1, 2026 17:16
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Performance profiles for profiler.firefox.com

Benchmarks (14)
  • neqo-bin-main: pr · base
  • neqo-common-decoder: pr · base
  • neqo-http3-streams_simulated: pr · base
  • neqo-http3-streams_walltime: pr · base
  • neqo-transport-frame_decode: pr · base
  • neqo-transport-min_bandwidth: pr · base
  • neqo-transport-pacer: pr · base
  • neqo-transport-packet_codec: pr · base
  • neqo-transport-range_tracker: pr · base
  • neqo-transport-rx_stream_orderer: pr · base
  • neqo-transport-send_streams: pr · base
  • neqo-transport-sent_packets: pr · base
  • neqo-transport-transfer_simulated: pr · base
  • neqo-transport-transfer_walltime: pr · base
Comparisons (5)

@mxinden
mxinden added this pull request to the merge queue Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Benchmark results

No significant performance differences relative to 5257f92.

All results
streams/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 severe
streams/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 mild
transfer/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 mild

Download data for profiler.firefox.com or download performance comparison data.

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Failed Interop Tests

QUIC Interop Runner, client vs. server, differences relative to main at 5989f80.

neqo-pr as clientneqo-pr as server
neqo-pr vs. go-x-net: BP BA
neqo-pr vs. haproxy: BP BA
neqo-pr vs. kwik: ⚠️C1
neqo-pr vs. lsquic: L1 C1 🚀BP
neqo-pr vs. msquic: A L1 C1
neqo-pr vs. mvfst: A BA
neqo-pr vs. neqo: A
neqo-pr vs. nginx: BP BA
neqo-pr vs. ngtcp2: CM
neqo-pr vs. picoquic: A 🚀BP
neqo-pr vs. quic-go: A
neqo-pr vs. quic-zig: ⚠️B
neqo-pr vs. quiche: BP BA
neqo-pr vs. s2n-quic: CM
neqo-pr vs. tquic: S BP BA
neqo-pr vs. xquic: S R Z A L1 C1 🚀BP
aioquic vs. neqo-pr: 🚀C1 CM
go-x-net vs. neqo-pr: CM
kwik vs. neqo-pr: BP BA CM
lsquic vs. neqo-pr: ⚠️L1
msquic vs. neqo-pr: CM
mvfst vs. neqo-pr: Z L1 C1 CM
neqo vs. neqo-pr: A
openssl vs. neqo-pr: LR M A CM
quic-go vs. neqo-pr: CM
quiche vs. neqo-pr: 🚀C1 CM
quinn vs. neqo-pr: 🚀L1 V2 CM
s2n-quic vs. neqo-pr: CM
tquic vs. neqo-pr: CM
xquic vs. neqo-pr: M CM
All results

Succeeded Interop Tests

QUIC Interop Runner, client vs. server

neqo-pr as client

neqo-pr as server

Unsupported Interop Tests

QUIC Interop Runner, client vs. server

neqo-pr as client

neqo-pr as server

Merged via the queue into mozilla:main with commit 2d9598a Sep 1, 2026
219 of 224 checks passed
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Client/server transfer results

Performance differences relative to 5257f92.

Transfer of 33554432 bytes over loopback, min. 100 runs. All unit-less numbers are in milliseconds.

Client vs. server Mean±σ Min–Max Median±MAD MiB/s±σ ΔMedian
neqo-neqo-newreno 77.3 ± 2.3 71.4 – 83.5 77.0 ± 1.7 413.9 ± 12.5 💔 +0.8 (+1.0%)
neqo-neqo-newreno-nopacing 79.8 ± 3.0 72.1 – 88.5 79.3 ± 1.7 401.0 ± 15.3 💔 +1.1 (+1.5%)

Table above only shows statistically significant changes. See all results below.

All results

Transfer of 33554432 bytes over loopback, min. 100 runs. All unit-less numbers are in milliseconds.

Client vs. server Mean±σ Min–Max Median±MAD MiB/s±σ ΔMedian
google-google 461.2 ± 2.9 456.7 – 473.9 460.5 ± 2.0 69.4 ± 0.4
google-neqo-cubic 267.4 ± 1.6 263.1 – 273.8 267.3 ± 1.1 119.7 ± 0.7 +0.6 (+0.2%)
neqo-google-cubic ⚠️ 762.1 ± 7.0 698.8 – 770.8 762.2 ± 2.9 42.0 ± 0.4 +0.0 (+0.0%)
neqo-neqo-cubic 77.4 ± 2.1 72.5 – 85.3 77.3 ± 1.8 413.3 ± 11.0 -0.2 (-0.2%)
neqo-neqo-cubic-nopacing 78.7 ± 3.2 71.9 – 89.3 78.3 ± 2.3 406.8 ± 16.3 -0.6 (-0.7%)
neqo-neqo-newreno 77.3 ± 2.3 71.4 – 83.5 77.0 ± 1.7 413.9 ± 12.5 💔 +0.8 (+1.0%)
neqo-neqo-newreno-nopacing 79.8 ± 3.0 72.1 – 88.5 79.3 ± 1.7 401.0 ± 15.3 💔 +1.1 (+1.5%)
neqo-quiche-cubic 193.7 ± 2.0 189.9 – 201.0 193.6 ± 1.6 165.2 ± 1.7 +0.3 (+0.2%)
neqo-s2n-cubic ⚠️ 213.8 ± 2.1 208.2 – 227.2 213.6 ± 1.3 149.7 ± 1.5 -1.0 (-0.5%)
quiche-neqo-cubic ⚠️ 137.8 ± 4.5 132.7 – 167.4 137.3 ± 1.0 232.2 ± 7.6 +0.7 (+0.5%)
quiche-quiche 135.6 ± 3.0 130.2 – 144.4 135.5 ± 3.0 235.9 ± 5.2
s2n-neqo-cubic 216.8 ± 1.7 212.3 – 222.2 216.5 ± 1.6 147.6 ± 1.2 -0.7 (-0.3%)
s2n-s2n ⚠️ 292.3 ± 24.8 277.3 – 385.8 285.5 ± 2.9 109.5 ± 9.3

Download data for profiler.firefox.com or download performance comparison data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants