Repository navigation
perf(scan): skip element payloads for list length expressions - #10759
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
There was a problem hiding this comment.
The structural-read approach preserves results while avoiding element payload I/O. Extra metadata requests can increase latency for cold scans with small list values; reusing a Dataset session can amortize that cost.
Please mark this PR with the breaking-change label: lance_encoding::decoder::DecoderConfig and CoreFieldDecoderStrategy gain a list_structure field, so callers using exhaustive struct literals must initialize it.
Remote FilteredRead plans dropped the list-structure demand introduced by #10759. After serialization, length and nonempty queries returned correct results but fetched element payloads again. Carry the field IDs and Length/NonEmpty modes through the execution protobuf, reject invalid modes, and keep the settings local to the read while preserving executor reader defaults. Validation: 42 filtered-read protobuf tests pass, including four multi-fragment serialized execution tests that fail on the parent because actual requests overlap image payloads. They cover both planning modes, NULL/empty lists and elements, and ordinary reads after structural requests. Mode/default/invalid-input cases, generated-protobuf consistency, proto comment lint, formatting and full workspace strict Clippy with Substrait also pass. This is an execution-wire change, not a persisted-format change. Old executors can ignore the new field and preserve results while losing the optimization. Generated Rust `FilteredReadOptionsProto` gains `list_structure` and no longer derives `Eq`/`Hash`; exhaustive struct literals must adapt. This is a prerequisite for Sophon adoption. No production rollout or new performance claim is included.
Downstream workspaces adopting Lance 15.0.0-beta.11 currently also resolve beta.10 because the SDK pins every Lance crate exactly. This produces incompatible Lance types across the SDK and the consumer. Update the workspace pins and lockfile to the published [v15.0.0-beta.11](https://github.com/lance-format/lance/releases/tag/v15.0.0-beta.11). This release includes payload-free list length reads and preserves those read modes across serialized plans (lance-format/lance#10759, lance-format/lance#10766). Existing feature flags and unrelated locked packages are unchanged. The release also includes the metric/k-dependent search-effort calibration from lance-format/lance#10695. Update the Node and Python execution tests to its exact probe budgets (for example, effort 0.25 with L2, k=8 and Auto=6 now probes 4 partitions), and cover the 0.1 tier. Recall, caller bounds and probe-precedence assertions remain in place. Validation: - `cargo fmt --all --check` - `cargo clippy --quiet --features remote --tests --examples` - Downstream metadata fixture with SDK source and the released Lance beta.11 path overrides resolves exactly one Lance version. - `cargo test --quiet --features remote --tests`: 2,271 passed, 0 failed, 79 existing ignored tests. - Node native/TypeScript build, lint and API documentation generation passed; 41 query tests passed. - Python native binding build and package Ruff checks passed; 208 query tests passed, 1 slow test deselected, 5 existing deprecation warnings. - Rust results remain applicable: the follow-up changes only binding tests, with product source and dependency graph unchanged from the tested dependency update. Repository-root Ruff currently reports 59 lint findings and 6 formatting failures in untouched documentation snippets. Their blobs match the PR base; the changed Python test and the entire Python package pass lint/format checks.
…#10669) Closes #10668. Writers before 13.0.0 could store a `0x00` control-word byte before each value of a full-zip page whose layout records no control-word bits. The reader takes that layout as NIL, so variable-width columns fail to read and fixed-width columns read shifted values. The decoder now marks such pages as padded and skips that byte: - Fixed width: a page with no repetition index that holds exactly `rows * (bytes_per_value + 1)` bytes. - Variable width: the NIL walk is retried with padding only after it fails. If the retry fails too, the original error is returned. Value reads reject a non-zero padding byte. A padded variable-width page whose NIL walk happens to succeed is still read as NIL, as before. For example, a read range holding one value of length L (L < 2^24) followed by exactly 255·L − 1 empty values returns the first value as 256·L bytes. ## `array_length` on NIL pages The list structure path from #10759 built an empty def buffer for a full-zip `FixedSizeList` page with nullable layers and a NIL control word, so `array_length` failed with `Incorrect length of values buffer for FixedSizeListArray`. The current writer emits such a page whenever a page of such a column has no nulls, and the padded pages have the same shape. That path now reads a NIL page as all valid, as the value path does. ## Tests - `test_v4_0_1_merge_insert_padded_control_words` scans a binary column that pylance 4.0.1 wrote through a `merge_insert` updating only some columns (#6338). `test_v11_0_0_fullzip_padded_control_words` reads pylance 11.0.0 `FixedSizeList<Struct>` columns with a `large_binary` or a `FixedSizeList<float32, 128>` child through scan, 3-row batches and take. The generators assert the defect is still written. Without the recovery, both tests fail with a corrupt-file error. `test_v11_0_0_fullzip_padded_control_words_list_length` runs `array_length` on the 11.0.0 columns. - `test_list_structure_fixed_outer` gains two full-zip cases from the current writer whose second file has no nulls. They fail without the list structure change. - `variable_full_zip_reads_nil_page`, `variable_full_zip_rejects_nonzero_padding`, `fixed_full_zip_reads_padded_nil_page`, `test_has_padded_fixed_control_words`: pages read whole or in parts, non-zero padding, and the fixed-width size check. I also checked by hand that this branch reads padded files written by pylance 2.0.0, 4.0.1, 6.0.1, 11.0.0 and 12.0.0, which 14.0.2 can't read or reads wrong. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Queries such as
array_length(images)andarray_length(images) > 0currently read list element payloads even though their results depend only on structure. Structural-format scans now compute list lengths, nonempty predicates, and NULL checks without reading element values, for every list element type the format supports, including nested lists, structs, maps, dictionaries, and blobs.The scanner proves that no expression consumes omitted values; otherwise it uses ordinary reads. FullZip reads row indexes and control/length headers; MiniBlock reads chunk headers and repetition/definition streams; constant, sparse, and blob pages omit value storage. Exact metadata reads avoid small-file prefetch and coalescing across payload gaps. Cached structural state is isolated from normal value decoding.
To limit the latency cost of small reads, adjacent FullZip control/length headers share a request, simple fixed scalar lists derive lengths from row spans, and independent page loads overlap in order with a 16-page bound within the requested batch. Structural header bytes use the existing file-scoped cache and its capacity/admission policy. The cache owns exact bytes rather than retaining larger sliced allocations.
Nested FixedSizeList compositions preserve enclosing null/empty markers in expanded row coordinates and derive decoded element counts from the child array. Empty structs retain sparse validity and existing dense row-count behavior. No file-layout or protobuf changes. Legacy array-format readers retain ordinary reads; this does not add types older writers reject, such as empty structs inside V2.2 lists.
Validation at
810f95b4da2dbafcdb4bbc13714e81fda9da0cfc(macOS arm64, pinned Rust 1.98.1):cargo fmt --all,cargo clippy --all --tests --benches -- -D warnings, and CI-profile Clippy with the union of all workspace features and all targets passed. Commit hooks passed.Performance measurements compare pre-PR baseline
1f1a2ac0d008df3239fb4f5263f5009326233f38with this head. Both use the identicalrust/lance/benches/list_structure.rsharness (SHA256e65d13224d10034927e5309aed0386ab2184693900d7392a7a9ea19931db56c8), lockfile, andrelease-no-ltoprofile for this I/O-bound experiment. The client is macOS arm64, 16 logical CPUs, 64 GiB RAM, reading synthetic S3 data in us-west-2; Tokio and Lance CPU pools each use 4 threads, batch size 32, readahead 2, I/O buffer 128 MiB. Each fixture has 128 rows in 4 fragments with NULL/empty lists and nullable elements: binary/fixed-binary use 8 elements of 256 KiB; small binary uses 8 elements of 128 B; integer uses 512 elements. Unrelated projected payloads are 16 KiB per row. Native file inspection confirms the actual codecs shown below; the frozen small-binary fixture's historical name contains “fullzip” but its actual encoding is MiniBlock.Three independent processes per variant/scenario, alternating baseline/PR order by trial. Each process performs a first scan and a second scan sharing the Dataset session. “New” excludes Dataset manifest open from the query timer and does not mean a flushed remote cache; “reused” measures the same session. C is concurrent queries and S is the id-modulo filter threshold, not exact output selectivity. Values are medians; latency brackets show min/max. Ratios describe these samples, not a statistically established gain when trial ranges overlap. Both binaries have identical allocation tracking and request recording, so these are instrumented client observations, not production ZEFR replay or server throughput acceptance.
Whole-process RSS is a high-water mark; live Rust allocation bytes are measured separately per round. Memory figures above use the first scan of a fresh process. The cache trades a bounded amount of metadata memory for avoiding repeated requests. Smaller payloads need not reduce RSS.
Observed read bytes and requests
Uncached variable-length FullZip lists still need dependent header reads. Cold MiniBlock reads need headers before level streams and can remain slower than reading a small complete value page. The no-payload contract is preserved; the implementation does not hide these costs by fetching value gaps. Full/scalar controls and mixed/filter/concurrency cases are included above, with observed regressions and variability retained. Production was not modified.
A separate local-file control used the same binaries, frozen fixtures, and scan configuration after S3 measurements, with five fresh processes per variant/scenario and alternating order. OS caches were not flushed. Medians and min/max ranges below show that ordinary full reads are similar locally; S3 full-read median differences (1.09x new and 1.17x reused) have overlapping trial ranges and are not sufficient to attribute a stable regression. Small-list structural processing still adds some local CPU/request overhead.
FixedSizeBinary still requires valid typed placeholder storage, so omitting its payload I/O does not eliminate its allocation cost. Cold-read tradeoffs remain documented here; further performance optimizations will be separate PRs.