Skip to content

Faster byte range cache - #6683

Merged
PSeitz-dd merged 8 commits into
quickwit-oss:mainfrom
PSeitz:faster_byte_range_cache
Aug 17, 2026
Merged

Faster byte range cache#6683
PSeitz-dd merged 8 commits into
quickwit-oss:mainfrom
PSeitz:faster_byte_range_cache

Conversation

@PSeitz

@PSeitz PSeitz commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Optimize byte range cache lookups.

In regex queries we have a lot of FileHandle::read_bytes lookups, which are passed to NeedMutByteRangeCache::get_slice. The path comparison was very expensive in these cases, although a lookup will never cross path boundaries.

This PR removes the repeated path lookups by moving it to one layer above to the FileHandle

Screenshot 2026-08-12 at 20 47 40

PSeitz added 3 commits August 12, 2026 17:19
Partition cached ranges by path using an FxHashMap so range lookups only
compare integer offsets within the selected file.
Resolve each path's cache when opening a file so range reads avoid repeated path lookups.
@PSeitz
PSeitz requested review from a team as code owners August 12, 2026 12:47
Comment on lines +47 to +50
if Self::get_block(&self.blocks, byte_range.start, byte_range.end).is_none() {
Self::merge_ranges(&mut self.blocks, byte_range.start, byte_range.end)?;
}
let (block_start, value) = Self::get_block(&self.blocks, byte_range.start, byte_range.end)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if get_block was Some the first time, we call it again immediately rather than keeping the result ?!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

changed it to a single lookup

Comment on lines +136 to +137
fn get_block(
blocks: &BTreeMap<usize, CacheValue>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why does this not take &self? borrow checker issues?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

no reason really, changed it to self

not relevant here, but fun fact: passing function parameters proves to the compiler these function parameter don't alias and produces better assembly

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so passing 3-4 args instead of a single self that contains those 3-4 args can generate better assembly because there are more NoAliases in the llvm IR?
that's... surprising

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, more info here: rust-lang/rust#149670
I encountered it with a 30% regression on term aggregations

They could prove they don't alias, but it's too hard apparently

@PSeitz-dd
PSeitz-dd enabled auto-merge (squash) August 17, 2026 02:13
@PSeitz-dd
PSeitz-dd merged commit b419081 into quickwit-oss:main Aug 17, 2026
5 checks passed
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.

3 participants