Skip to content

Prefetch reader #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2025
Merged

Prefetch reader #18

merged 1 commit into from
Feb 25, 2025

Conversation

kylebarron
Copy link
Member

@kylebarron kylebarron commented Feb 25, 2025

Allows for fetching first X kb of a file, and then delegating further requests to this cached buffer.

This caused the Python file open to reduce from 2.5 minutes to 0.7sec

cc @geospatial-jeff. Because this is implemented as a middleware, we could implement whatever sort of cache we want here, like a block cache.


impl PrefetchReader {
pub async fn new(mut reader: Box<dyn AsyncFileReader>, prefetch: u64) -> Result<Self> {
let buffer = reader.get_bytes(0..prefetch).await?;
Copy link
Member Author

Choose a reason for hiding this comment

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

We pre-fetch this prefix of the file when "opening" this reader layer

Comment on lines +133 to +135
let usize_range = range.start as usize..range.end as usize;
let result = self.buffer.slice(usize_range);
async { Ok(result) }.boxed()
Copy link
Member Author

Choose a reason for hiding this comment

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

Then if the start and end of the requested range are fully within the existing cached buffer, we return that slice.

@kylebarron kylebarron merged commit eddea60 into main Feb 25, 2025
1 check passed
@kylebarron kylebarron deleted the kyle/prefetch-reader branch February 25, 2025 21:50
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