Skip to content

Commit

Permalink
refactor: deduplicate events
Browse files Browse the repository at this point in the history
See whether mozilla#921 has any performance impact.
  • Loading branch information
mxinden committed Apr 11, 2024
1 parent c004359 commit 137f029
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
35 changes: 14 additions & 21 deletions neqo-http3/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,21 @@ impl Http3Server {
fn process_http3(&mut self, now: Instant) {
qtrace!([self], "Process http3 internal.");
let mut active_conns = self.server.active_connections();

// We need to find connections that needs to be process on http3 level.
let mut http3_active: Vec<ActiveConnectionRef> = self
.http3_handlers
.iter()
.filter_map(|(conn, handler)| {
if handler.borrow_mut().should_be_processed() && !active_conns.contains(conn) {
Some(conn)
} else {
None
}
})
.cloned()
.collect();
// For http_active connection we need to put them in neqo-transport's server
// waiting queue.
active_conns.append(&mut http3_active);
active_conns.dedup();
active_conns
.iter()
.for_each(|conn| self.server.add_to_waiting(conn));
active_conns.extend(
// We need to find connections that needs to be process on http3 level.
self.http3_handlers
.iter()
.filter_map(|(conn, handler)| {
if handler.borrow_mut().should_be_processed() {
Some(conn)
} else {
None
}
})
.cloned(),
);
for mut conn in active_conns {
self.server.add_to_waiting(&conn);
self.process_events(&mut conn, now);
}
}
Expand Down
4 changes: 2 additions & 2 deletions neqo-transport/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,8 @@ impl Server {

/// This lists the connections that have received new events
/// as a result of calling `process()`.
pub fn active_connections(&mut self) -> Vec<ActiveConnectionRef> {
mem::take(&mut self.active).into_iter().collect()
pub fn active_connections(&mut self) -> HashSet<ActiveConnectionRef> {
mem::take(&mut self.active)
}

pub fn add_to_waiting(&mut self, c: &ActiveConnectionRef) {
Expand Down
24 changes: 22 additions & 2 deletions neqo-transport/tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,17 @@ fn zero_rtt() {
// The server will have received two STREAM frames now if it processed both packets.
let active = server.active_connections();
assert_eq!(active.len(), 1);
assert_eq!(active[0].borrow().stats().frame_rx.stream, 2);
assert_eq!(
active
.iter()
.next()
.unwrap()
.borrow()
.stats()
.frame_rx
.stream,
2
);

// Complete the handshake. As the client was pacing 0-RTT packets, extend the time
// a little so that the pacer doesn't prevent the Finished from being sent.
Expand All @@ -321,7 +331,17 @@ fn zero_rtt() {
mem::drop(server.process(Some(&c4), now));
let active = server.active_connections();
assert_eq!(active.len(), 1);
assert_eq!(active[0].borrow().stats().frame_rx.stream, 2);
assert_eq!(
active
.iter()
.next()
.unwrap()
.borrow()
.stats()
.frame_rx
.stream,
2
);
}

#[test]
Expand Down

0 comments on commit 137f029

Please sign in to comment.