Skip to content

Commit 616a9a7

Browse files
committed
proto: Cache Send.write chunks vec
This is a minor optimization to avoid repeated re-allocation.
1 parent fcd3ce7 commit 616a9a7

File tree

1 file changed

+6
-3
lines changed
  • quinn-proto/src/connection/streams

1 file changed

+6
-3
lines changed

quinn-proto/src/connection/streams/send.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub(super) struct Send {
1515
pub(super) connection_blocked: bool,
1616
/// The reason the peer wants us to stop, if `STOP_SENDING` was received
1717
pub(super) stop_reason: Option<VarInt>,
18+
/// Reusable buf for usage within `write`--empty between calls to `self.write`
19+
chunks: Vec<Bytes>,
1820
}
1921

2022
impl Send {
@@ -27,6 +29,7 @@ impl Send {
2729
fin_pending: false,
2830
connection_blocked: false,
2931
stop_reason: None,
32+
chunks: Vec::new(),
3033
})
3134
}
3235

@@ -66,12 +69,12 @@ impl Send {
6669
}
6770
let limit = limit.min(budget) as usize;
6871

69-
let mut chunks = Vec::new();
70-
let source_output = source(limit, &mut chunks);
72+
debug_assert!(self.chunks.is_empty());
73+
let source_output = source(limit, &mut self.chunks);
7174

7275
let mut written = 0;
7376

74-
for mut chunk in chunks.drain(..) {
77+
for mut chunk in self.chunks.drain(..) {
7578
let prefix = chunk.split_to(chunk.len().min(limit - written));
7679
written += prefix.len();
7780
self.pending.write(prefix);

0 commit comments

Comments
 (0)