Skip to content

Commit

Permalink
perf(s2n-quic-core): implement copy avoidance for reassembler (#2134)
Browse files Browse the repository at this point in the history
  • Loading branch information
camshaft authored Feb 22, 2024
1 parent c7108ce commit b793931
Show file tree
Hide file tree
Showing 8 changed files with 459 additions and 468 deletions.
21 changes: 21 additions & 0 deletions quic/s2n-quic-core/src/buffer/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@ pub trait Reader: Storage {
.map_or(false, |fin| fin == self.current_offset())
}

/// Skips the data in the reader until `offset` is reached, or the reader storage is exhausted.
#[inline]
fn skip_until(&mut self, offset: VarInt) -> Result<(), Self::Error> {
ensure!(offset > self.current_offset(), Ok(()));

while let Some(len) = offset.checked_sub(self.current_offset()) {
let len = len.as_u64();

// we don't need to skip anything if the difference is 0
ensure!(len > 0, break);

// clamp the len to usize
let len = (usize::MAX as u64).min(len) as usize;
let _chunk = self.read_chunk(len)?;

ensure!(!self.buffer_is_empty(), break);
}

Ok(())
}

/// Limits the maximum offset that the caller can read from the reader
#[inline]
fn with_max_data(&mut self, max_data: VarInt) -> Limit<Self> {
Expand Down
2 changes: 1 addition & 1 deletion quic/s2n-quic-core/src/buffer/reader/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub use io_slice::IoSlice;
pub use tracked::Tracked;

pub trait Storage {
type Error;
type Error: 'static;

/// Returns the length of the chunk
fn buffered_len(&self) -> usize;
Expand Down
Loading

0 comments on commit b793931

Please sign in to comment.