Skip to content

Exponential overflow header buffer - #83

Closed
kylebarron wants to merge 9 commits into
mainfrom
kyle/exponential-overflow-header-buffer
Closed

kylebarron wants to merge 9 commits into
mainfrom
kyle/exponential-overflow-header-buffer

Conversation

@kylebarron

Copy link
Copy Markdown
Member

Changes

  • Updates AsyncFileReader to use &mut self instead of &self on the trait methods. This is necessary so that the buffer can be mutated when fetching the overflow, while also adding it to the cached buffers
  • Use Box instead of Arc in reader code, now that we need mutability of the reader.
  • Updates the tokio integration to implement AsyncFileReader directly on anything that implements AsyncRead and AsyncSeek. We don't need a wrapper object now that we use &mut self ourselves.
  • Add test to verify overflow handling

This PR is not made on top of #82, but I think some mix of this and #82 makes sense.

Comment thread src/reader.rs Outdated
Comment on lines +250 to +259
async fn expand_prefetch(&mut self, range: Range<u64>) -> AsyncTiffResult<Bytes> {
let existing_buffer_length = self.buffer_length() as u64;
let additional_fetch =
(existing_buffer_length as f64).powf(self.overflow_fetch_exponent) as u64;

// Make sure that we fetch at least the entire desired range
let new_range =
existing_buffer_length..range.end.max(existing_buffer_length + additional_fetch);
let buffer = self.reader.get_metadata_bytes(new_range).await?;
self.buffers.push(buffer);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we request the overflow and add it to the existing buffering (self.buffers.push(buffer))

Comment thread src/reader.rs Outdated
/// ## Panics
///
/// If the range does not fall completely within the pre-cached buffers.
fn buffer_slice(&self, range: Range<u64>) -> Bytes {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads from the existing buffers, handling a cross-buffer merge in case the input request overlaps multiple of self.buffers

@kylebarron

Copy link
Copy Markdown
Member Author

Closing in favor of #140

@kylebarron kylebarron closed this Nov 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant