Skip to content

Commit

Permalink
Optimize the stream frame write method (merge request !127) (#21)
Browse files Browse the repository at this point in the history
Squash merge branch 'optimize_stream_write' into 'master'
Optimize the stream frame write method

Co-authored-by: ivanfywang <ivanfywang@tencent.com>
  • Loading branch information
wangfuyu and ivanfywang authored Nov 3, 2023
1 parent 05c56e7 commit 3928ff6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
15 changes: 5 additions & 10 deletions src/connection/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,7 @@ impl Connection {
let out = &mut out[st.written..];
if (pkt_type != PacketType::OneRTT && pkt_type != PacketType::ZeroRTT)
|| self.is_closing()
|| out.len() <= frame::MAX_STREAM_OVERHEAD
|| out.len() <= frame::MIN_STREAM_OVERHEAD
|| !self.paths.get(path_id)?.active()
{
return Ok(());
Expand All @@ -2183,8 +2183,8 @@ impl Connection {

while let Some(stream_id) = self.streams.peek_sendable() {
let stream = match self.streams.get_mut(stream_id) {
// Avoid sending frames for streams that were already stopped.
Some(v) if !v.send.is_stopped() => v,
// We should not send frames for streams that were already stopped.
Some(s) if !s.send.is_stopped() => s,
_ => {
self.streams.remove_sendable();
continue;
Expand All @@ -2203,10 +2203,9 @@ impl Connection {
// 3. encode the frame header with the updated frame header segments.
let frame_hdr_len = frame::stream_header_wire_len(stream_id, stream_off);

// TODO: review again
// If the buffer is too short, we won't attempt to write any more stream frames into it.
if cap.checked_sub(frame_hdr_len).is_none() {
self.streams.remove_sendable();
continue;
break;
}

// Read stream data and write into the packet buffer directly.
Expand Down Expand Up @@ -2250,10 +2249,6 @@ impl Connection {
if !stream.is_sendable() {
self.streams.remove_sendable();
}

if cap <= frame::MAX_STREAM_OVERHEAD {
break;
}
}

Ok(())
Expand Down
1 change: 1 addition & 0 deletions src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub(crate) const MAX_STREAM_SIZE: u64 = 1 << 62;

pub(crate) const MAX_CRYPTO_OVERHEAD: usize = 8;
pub(crate) const MAX_STREAM_OVERHEAD: usize = 12;
pub(crate) const MIN_STREAM_OVERHEAD: usize = 5;

/// The QUIC frame is a unit of structured protocol information. Frames are
/// contained in QUIC packets.
Expand Down
2 changes: 0 additions & 2 deletions src/h3/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,6 @@ impl Http3Connection {
.local_initialized()
{
// Stream header has not been sent yet, should not send body now.
// TODO: revisit here, return Err(Http3Error::Done) more suitable?
return Err(Http3Error::FrameUnexpected);
}

Expand Down Expand Up @@ -1971,7 +1970,6 @@ impl Http3Connection {
}

// Process known critical streams, including HTTP/3 control, QPACK encoder/decoder streams.
// TODO: optimize here.
match self.process_critical_streams(conn) {
Ok(ev) => return Ok(ev),
// Everything is fine, continue.
Expand Down

0 comments on commit 3928ff6

Please sign in to comment.