Skip to content

perf(file): reduce metadata read scheduling rounds - #9169

Closed
Ali2Arslan wants to merge 6 commits into
lance-format:mainfrom
Ali2Arslan:feat/file-metadata-open-hint
Closed

Ali2Arslan wants to merge 6 commits into
lance-format:mainfrom
Ali2Arslan:feat/file-metadata-open-hint

Conversation

@Ali2Arslan

@Ali2Arslan Ali2Arslan commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Status

Draft and stacked on #9168. After the format contract merges, rebase away its duplicated contract changes and mark this PR ready.

What this does

  • Adds intent-specific, private-field options around one reusable tail-read planner.
  • Full metadata opens use the exact persisted suffix size to schedule every required metadata byte immediately.
  • Projected data-file opens derive the initial range from existing manifest column mappings: baseline_tail + 16 * estimated_physical_columns.
  • Footer offsets and counts remain authoritative. Absent, stale, oversized, underestimated, or inconsistent hints retain footer-directed decoding.
  • Hint-driven overread is admitted only when the complete planned tail fits the scheduler's configured unread-I/O byte budget. This bounds corrupt in-range hints without conflating the policy with max_iop_size; admitted logical ranges may still split concurrently. A zero/unbounded byte-backpressure setting conservatively uses the baseline footer path.
  • Fallbacks extend one accumulated suffix with only the missing prefix. CMO and GBO bytes are coalesced instead of issuing overlapping reads.
  • Large logical ranges remain eligible for FileScheduler splitting into concurrent physical requests; dependency depth and physical request count remain separate concerns.
  • Speculative prefetching retains global-buffer bytes only from the original baseline tail window.
  • Current-format writers return an opaque, evolution-safe write result and propagate the exact suffix through data files, replacements, concat/staged parts, binary copy, scalar indices, and modern vector indices.
  • Python and Java models preserve the advisory value across transaction and fragment round trips while keeping existing constructors compatible; zero remains the unavailable sentinel.
  • Scalar index stores use one typed per-file hint map instead of parallel maps.
  • Modern IVF cold opens dispatch the root reader once and prefetch exact root and auxiliary metadata concurrently; both decoded readers are reused.
  • Legacy writers and readers are unchanged.

I/O behavior covered by tests

  • Exact full-metadata hint: 2 dependent reads -> 1 scheduling round.
  • Correct projected column estimate: tail + CMO dependency -> 1 scheduling round.
  • Underestimates extend only the missing prefix, with no duplicate bytes.
  • Multi-step full-metadata fallback maintains one accumulated suffix.
  • Overestimates and stale/oversized values preserve correct footer-directed decoding.
  • A corrupt in-range exact hint and a pathological projected-column estimate cannot trigger a logical read larger than the configured scheduler byte budget.
  • FileScheduler request splitting remains unconstrained by the hint planner.
  • Stale over-prefetch does not increase retained global-buffer cache residency.
  • Modern vector root and auxiliary readers issue no duplicate request signatures; legacy vector opens still succeed.
  • Missing hints in older manifests and staged-part checkpoints remain supported.

Validation

  • cargo test -p lance-file
  • cargo test -p lance-index metadata_hint_removes_scalar_index_footer_dependency
  • cargo test -p lance concatenates_parts_in_caller_order_without_reusing_staging_files
  • cargo test -p lance test_hnsw_index_records_file_sizes
  • cargo test -p lance test_legacy_non_divisible_pq_search
  • uv run pytest python/tests/test_fragment.py::test_fragment_meta python/tests/test_commit_index.py::test_commit_index_with_files python/tests/test_table_ops.py::test_data_file_create_basic python/tests/test_table_ops.py::test_data_file_create_end_to_end
  • uv run make lint
  • cargo clippy --tests --manifest-path java/lance-jni/Cargo.toml -- -D warnings
  • ./mvnw -Dtest=FragmentTest,TransactionTest test
  • cargo clippy --all --tests --benches -- -D warnings

Made with Cursor

@github-actions github-actions Bot added A-index Vector index, linalg, tokenizer A-encoding Encoding, IO, file reader/writer A-format On-disk format: protos and format spec docs format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). performance labels Sep 11, 2026
@github-actions github-actions Bot added A-python Python bindings A-java Java bindings + JNI labels Sep 12, 2026
Xuanwo added a commit that referenced this pull request Oct 23, 2026
## Proposal

Add one advisory `file_metadata_size_bytes` value to `DataFile` and
`IndexFile`. For a Lance file of format version 2.0 or later, it is the
file size minus the position of global buffer 0, which holds the file's
`FileDescriptor`. That position is stored in the first entry of the
global buffer offset table, which the footer locates. The value is
always zero for legacy (0.1) files and for index files in other formats;
zero also means unknown. Writers record either this exact value or zero.

Footer offsets and counts remain authoritative. Readers ignore a value
larger than the file and read any metadata the footer references outside
the hinted range.

## Rationale

A full metadata open always needs this complete suffix. Recording its
exact size lets a reader schedule the required bytes immediately instead
of waiting for a footer read before scheduling the metadata prefix. This
optimizes dependency depth independently of physical request count; the
scheduler may still split a large logical range into concurrent
requests.

Projected data-file opens do not need another persisted value: an
implementation can estimate the CMO table from the manifest's existing
physical-column mappings and retain a prefix-only fallback.

## Compatibility

- Existing readers ignore the new protobuf fields.
- Existing writers encode zero by omission.
- New readers retain the ordinary footer-directed path when the value is
unusable.
- The Lance file bytes and footer grammar do not change.
- No feature flag or file-format version bump is required because the
value is advisory.
- The in-memory representation uses `Option<NonZeroU64>`, so the hint
occupies one `u64` slot.
- `DataFile` JSON always includes `file_metadata_size_bytes` (`null`
when unknown), like `file_size_bytes` and `base_id`. Python's `DataFile`
accepts and carries the value because `FragmentMetadata.from_json`
builds it from that JSON, for example for write progress and distributed
compaction.
- Java conversions and the Python `IndexFile` conversion initialize the
new fields as unavailable until the follow-up implementation propagates
them.

Per the format-change process, this PR contains only the durable
contract, documentation, and minimum compilation/round-trip updates. The
reader/writer implementation is prepared in #9169 and remains draft
until this change merges.

## Maintainer action

Gatekeeper requested the `breaking-change` label. GitHub does not permit
fork contributors to apply repository labels, so a maintainer must add
it.

## Validation

- `cargo test -p lance-table --lib -- test_to_json
test_intern_fragment_file_metadata_size_bytes
test_rewritten_index_roundtrips test_roundtrip_fragment
test_index_metadata_codec_roundtrip`
- `uv run pytest python/tests/test_fragment.py
python/tests/test_optimize.py
python/tests/test_dataset.py::test_dataset_progress`
- `cargo clippy --all --tests --benches -- -D warnings`
- `uv run make lint` (from `python/`)
- `python3 ci/check_proto_comments.py protos/table.proto
protos/fragment_metadata.proto`

Made with [Cursor](https://cursor.com)

---------

Co-authored-by: Cursor <[email protected]>
Co-authored-by: Xuanwo <[email protected]>
Xuanwo pushed a commit that referenced this pull request Oct 26, 2026
Concatenating many staged data-file parts serializes each part's
open/validation and then reads payloads one column at a time. For small
parts containing vector output and auxiliary columns, these dependent
object-store requests dominate concatenation.

This change opens up to `min(io_parallelism, 8)` parts concurrently
while preserving caller order and all existing validation, including
#10315's single-GET validation for small parts and HEAD validation for
larger parts. For modern files that fit within the existing read-batch
budget, it submits payload ranges across columns together, sorted by
physical offset, and restores their logical order before copying. Larger
files retain streaming reads. There are no file-format or public API
changes.

The metadata-hint work in #9169 addresses a different source of read
dependencies; this change does not require it.

### Performance

Current-head performance has not been remeasured after merging main,
including #10315's small-part single-GET validation. The earlier
measurements below apply only to the stated historical commits and are
not a performance claim for the merged head.

<details>
<summary>Historical benchmark before merging main</summary>

Measured `Dataset::concat_data_file_parts` only, from baseline
`c633e438c291dbf1781657a37ad489098438af21` to the earlier candidate
`276d0ff57c792ac633c910928efa8d3ed97d8d96`. Values are medians of three
paired rounds; lower latency is better.

| Scenario / metric | Baseline | Measured candidate (276d0ff) |
Historical benefit |
| --- | ---: | ---: | ---: |
| 140 parts / concat latency | 54.12 s | 32.37 s | 1.67x speedup |
| 640 parts / concat latency | 204.11 s | 40.72 s | 5.01x speedup |
| 20 large parts / concat latency | 12.15 s | 11.24 s | 1.08x speedup |

The same AWS m7i.8xlarge host (32 vCPUs, 128 GiB RAM), four-CPU process
affinity, and same-region S3 in us-east-1 were used for both builds,
with Rust 1.98.1 and the repository's `release-no-lto` profile for this
I/O-bound workload. Input was frozen output containing 1,000,000 rows, a
384-dimensional Float32 vector, and five auxiliary columns, written as
Lance 2.2. Twenty 50,000-row splits were subdivided into parts of at
most 8,192, 1,563, or 50,000 rows. These are controlled part layouts,
not a reconstruction of adaptive Function Engine output partitioning.

Each run used a fresh fixture and process, with alternating baseline/PR
order and rotating scenarios; no other builds ran during measurement.
Full Arrow equality across all rows and all six columns was checked
after concatenation, outside the timer. S3 cache state was not
controlled. Observed latency ranges were 48.99–54.30 s / 30.19–33.81 s
for 140 parts, 202.13–211.54 s / 40.62–56.00 s for 640 parts, and
12.00–12.28 s / 10.53–11.61 s for 20 parts (baseline / PR).

Network allowance counters increased in every 140-part and 20-part
observation window, so those results describe this host's network
budget. All six 640-part windows had zero allowance-exceeded increments.
Counter windows enclosed concatenation and excluded bulk result
validation; they were not exact phase boundaries. These results do not
measure end-to-end Function Engine refresh, upload, or checkpoint
performance.

Object-store read/HEAD calls fell from 840 to 420 for 140 parts and from
3,840 to 1,920 for 640 parts; the 20-part fallback remained at 200
calls. Output sizes and write-call counts were unchanged. Counts are at
the object-store layer, not retry-inclusive HTTP requests.

</details>

### Validation after merging main

Validated merge commit `25120495af468dad17496d881d087704e0ea45ed`,
including main `71a1b76581c340cd29fc6d837b36efead2afa23b`.

- 27 data-file-part tests, 22 concat tests, and 19 object-reader tests
passed on the combined tree.
- Both small-part and large-part concurrency tests also passed with
`LANCE_IO_THREADS=1`. The small-part case requires zero HEAD requests
and exactly one GET per part; both cases check bounded fanout and caller
order.
- Formatting and full workspace Clippy (`--all --tests --benches -- -D
warnings`) passed.
- The original full-value benchmark results above remain historical;
performance has not been remeasured for the merged head.

<details>
<summary>Validation commands (macOS ARM64, Rust 1.98.1)</summary>

```sh
cargo fmt --all -- --check
cargo test --locked -p lance --features tokio/test-util --lib dataset::tests::data_file_part
LANCE_IO_THREADS=1 cargo test --locked -p lance --features tokio/test-util --lib opens_parts_concurrently_with_bounded_fanout_and_caller_order
cargo test --locked -p lance-file --features lance-io/aws,lance-io/test-util,tokio/test-util --lib concat::tests
cargo test --locked -p lance-io --features test-util,tokio/test-util --lib object_reader::tests
cargo clippy --locked --all --tests --benches -- -D warnings
```

</details>
@Ali2Arslan

Copy link
Copy Markdown
Contributor Author

Closing this stale draft. It conflicts with main and I'm not pursuing it now.

@Ali2Arslan Ali2Arslan closed this Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-encoding Encoding, IO, file reader/writer A-format On-disk format: protos and format spec docs A-index Vector index, linalg, tokenizer A-java Java bindings + JNI A-python Python bindings format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant