Repository navigation
perf(index): cache index file metadata across opens - #9461
Merged
Merged
Conversation
`LanceIndexStore::open_index_file` always went through `open_self_described_reader`, which reads the file tail (footer, schema, column metadata) from object storage on every call. Scalar indexes re-open their files often: the BTree index creates a fresh lazy reader per search and opens the pages file on every page-cache miss, so each cold page read paid one or two extra round trips just to decode metadata it had decoded before. Cache the decoded `CachedFileMetadata` in the store's per-index metadata cache, keyed by the full object path (index files are immutable and live under a unique per-uuid directory). On a hit the reader is built with `FileReader::try_open_with_file_metadata` and the same `LanceEncodingsIo` wrapper the dispatch path uses, so no tail bytes are fetched. On a miss the file is opened through the existing dispatch path and the metadata from the opened reader is inserted. Legacy V1 files still fall through to the V1 reader and are not cached. Priority clones share the cache. This mirrors what dataset data files already do in `FileFragment` and benefits every scalar index type that opens files through `LanceIndexStore` without changing the `IndexStore` trait. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Contributor
There was a problem hiding this comment.
✅ Gate recommendation: approve.
Caching decoded current-format metadata at the index-store boundary removes the repeated-open I/O without changing file or API contracts. The cache remains scoped to immutable index paths, preserves the V1 fallback and reader options, and is size-accounted; focused coverage verifies zero-I/O reuse together with schema, data, projection, global-buffer, and existing update behavior. This centralized mechanism is preferable to duplicating reader retention across scalar index implementations.
Xuanwo
approved these changes
Sep 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
LanceIndexStore::open_index_filealways went throughopen_self_described_reader, which reads the file tail (footer, schema, column metadata) from object storage on every call. Scalar indexes re-open their files often: the BTree index creates a fresh lazy reader per search and openspage_data.lanceon every page-cache miss, so each cold page read paid one or two extra sequential round trips just to decode metadata it had already decoded before. Dataset data files already avoid this through the metadata cache; index files did not.Change
CachedFileMetadatain the store's per-index metadata cache, keyed by the full object path (index files are immutable and live under a unique per-uuid directory).FileReader::try_open_with_file_metadataand the sameLanceEncodingsIowrapper the dispatch path uses, so no tail bytes are fetched. On a miss the file is opened through the existing dispatch path and the metadata of the opened reader is inserted.with_io_priority) share the cache.IndexStoretrait or to any index implementation; every scalar index type that opens files throughLanceIndexStorebenefits.Validation
lance_format.rs: a second open of the same file through one store issues zero read requests (checked on both the object store IO tracker and the scheduler stats) and still returns correct rows/schema/projections; the cache is keyed by full path (two files in one store do not share metadata); a store with a fresh cache reads again.cargo test -p lance-index scalar::lance_format(30 passed),cargo test -p lance-index scalar::btree(45 passed),cargo test -p lance index::scalar --lib(47 passed).cargo clippy -p lance-index --tests --features lance-io/aws -- -D warningsclean (the plain invocation only reports pre-existing dead code inlance-io/src/object_store/throttle.rs).Benchmark
100M random Int64 rows in 1000 fragments, BTree with 24,659 pages, c7i.16xlarge in us-east-1, dataset on S3 (
us-east-1) and on local disk. Index state warm, each query hits a page that is not in the page cache; 300 queries, p50, lower is better. Baseline ismainat 00a8230, this PR is the same commit plus this change, both built and run on the same machine.S3 latency varies about +-40% between runs on this setup; the request and byte counts are exact and are the primary evidence. Hot-page queries are unchanged (0.6 to 0.7 ms).
🤖 Generated with Claude Code