Skip to content

Commit

Permalink
use split_to instead of cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Neto committed Oct 31, 2023
1 parent 1f09aed commit 9f7f942
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
3 changes: 1 addition & 2 deletions quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ impl Connection {
SpaceId::Data,
"PATH_CHALLENGE queued without 1-RTT keys"
);

buf.reserve(self.path.current_mtu() as usize);

let buf_capacity = buf.capacity();
Expand Down Expand Up @@ -686,7 +685,7 @@ impl Connection {
// (e.g. purely containing ACKs), modern memory allocators
// (e.g. mimalloc and jemalloc) will pool certain allocation sizes
// and therefore this is still rather efficient.
buf.reserve(max_datagrams * self.path.current_mtu() as usize - buf.capacity());
buf.reserve(max_datagrams * self.path.current_mtu() as usize);
}
num_datagrams += 1;
coalesce = true;
Expand Down
10 changes: 5 additions & 5 deletions quinn-proto/src/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ impl TestEndpoint {
self.conn_events.entry(ch).or_default().push_back(event);
}
DatagramEvent::Response(transmit) => {
let size = transmit.size;
self.outbound
.extend(split_transmit(transmit, buf.clone().freeze()));
buf.clear();
.extend(split_transmit(transmit, buf.split_to(size).freeze()));
}
}
}
Expand All @@ -378,10 +378,10 @@ impl TestEndpoint {
while let Some(event) = conn.poll_endpoint_events() {
endpoint_events.push((*ch, event));
}
while let Some(x) = conn.poll_transmit(now, MAX_DATAGRAMS, &mut buf) {
while let Some(transmit) = conn.poll_transmit(now, MAX_DATAGRAMS, &mut buf) {
let size = transmit.size;
self.outbound
.extend(split_transmit(x, buf.clone().freeze()));
buf.clear();
.extend(split_transmit(transmit, buf.split_to(size).freeze()));
}
self.timeout = conn.poll_timeout();
}
Expand Down
1 change: 0 additions & 1 deletion quinn/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,6 @@ impl State {
// See https://github.com/quinn-rs/quinn/issues/1126
return true;
}
buffer.clear();
}

false
Expand Down
10 changes: 6 additions & 4 deletions quinn/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,17 +444,19 @@ impl State {
.unwrap()
.send(ConnectionEvent::Proto(event));
}
Some(DatagramEvent::Response(t)) => {
Some(DatagramEvent::Response(transmit)) => {
// Limiting the memory usage for items queued in the outgoing queue from endpoint
// generated packets. Otherwise, we may see a build-up of the queue under test with
// flood of initial packets against the endpoint. The sender with the sender-limiter
// may not keep up the pace of these packets queued into the queue.
if self.transmit_queue_contents_len
< MAX_TRANSMIT_QUEUE_CONTENTS_LEN
{
let contents_len = buffer.len();
self.outgoing
.push_back(udp_transmit(t, buffer.clone().freeze()));
let contents_len = transmit.size;
self.outgoing.push_back(udp_transmit(
transmit,
buffer.split_to(contents_len).freeze(),
));
self.transmit_queue_contents_len = self
.transmit_queue_contents_len
.saturating_add(contents_len);
Expand Down

0 comments on commit 9f7f942

Please sign in to comment.