Skip to content

perf(scan): skip element payloads for list length expressions - #10759

Merged
BubbleCal merged 3 commits into
mainfrom
yang/t200-array-length-structure
Nov 5, 2026
Merged

BubbleCal merged 3 commits into
mainfrom
yang/t200-array-length-structure

Conversation

@BubbleCal

@BubbleCal BubbleCal commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Queries such as array_length(images) and array_length(images) > 0 currently 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):

  • Scanner structural matrix: 98 passed; original Arrow/DataFusion results are the oracle. Covers List/LargeList/FixedSizeList, NULL/empty lists and elements, nested dimensions/paths, slices, multiple fragments, deletions/indexed counts, mixed projections, and normal reads after structural reads.
  • Full encoding suite: 2,363 passed, 3 existing ignored. Includes safe header ranges, zero-width items, nullable fixed scalar spans, cache isolation, bounded concurrency/order, and error propagation.
  • File reader regressions: 107 passed, including 12 structural range cases. Tests locate payload bytes independently, assert actual FullZip/MiniBlock codecs, cover multiple pages/chunks and disjoint selections, and assert zero repeated structural I/O.
  • 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 1f1a2ac0d008df3239fb4f5263f5009326233f38 with this head. Both use the identical rust/lance/benches/list_structure.rs harness (SHA256 e65d13224d10034927e5309aed0386ab2184693900d7392a7a9ea19931db56c8), lockfile, and release-no-lto profile 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.

Scenario / metric (lower is better) Baseline This PR Benefit
Large binary / FullZip / length / Process peak RSS 477.59 MiB 51.25 MiB 9.32x less memory
Large binary / FullZip / length / Peak live Rust allocations 349.42 MiB 3.32 MiB 105.35x less memory
Large binary / FullZip / count / Process peak RSS 612.14 MiB 50.23 MiB 12.19x less memory
Large binary / FullZip / count / Peak live Rust allocations 324.29 MiB 1.02 MiB 318.55x less memory
Fixed binary / FullZip / length / Process peak RSS 615.34 MiB 159.14 MiB 3.87x less memory
Fixed binary / FullZip / length / Peak live Rust allocations 419.31 MiB 112.89 MiB 3.71x less memory
Large binary / FullZip / full / Process peak RSS 525.09 MiB 524.30 MiB Comparable medians
Large binary / FullZip / full / Peak live Rust allocations 355.00 MiB 354.89 MiB Comparable medians
Scenario / round latency (lower is better) Baseline This PR Benefit
Large binary / FullZip / count / C1 / S100 / new 11240 ms [11160 ms, 15623 ms] 3353 ms [3185 ms, 3894 ms] 3.35x speedup
Large binary / FullZip / count / C1 / S100 / reused 8785 ms [8542 ms, 10571 ms] 0.96 ms [0.93 ms, 2.23 ms] 9181.81x speedup
Large binary / FullZip / full / C1 / S100 / new 12081 ms [8496 ms, 12541 ms] 13194 ms [12442 ms, 15331 ms] 1.09x higher
Large binary / FullZip / full / C1 / S100 / reused 6854 ms [6435 ms, 13559 ms] 8037 ms [6813 ms, 12546 ms] 1.17x higher
Large binary / FullZip / length / C1 / S10 / new 10661 ms [4474 ms, 15738 ms] 7520 ms [7212 ms, 8618 ms] 1.42x speedup
Large binary / FullZip / length / C1 / S10 / reused 4953 ms [2903 ms, 5129 ms] 270 ms [266 ms, 293 ms] 18.33x speedup
Large binary / FullZip / length / C1 / S100 / new 14220 ms [9353 ms, 15544 ms] 13296 ms [13005 ms, 14233 ms] 1.07x speedup
Large binary / FullZip / length / C1 / S100 / reused 12782 ms [7235 ms, 16323 ms] 4.97 ms [3.90 ms, 5.46 ms] 2573.93x speedup
Large binary / FullZip / length / C4 / S100 / new 29865 ms [26499 ms, 49328 ms] 12980 ms [12883 ms, 15115 ms] 2.30x speedup
Large binary / FullZip / length / C4 / S100 / reused 25954 ms [25756 ms, 34456 ms] 7.83 ms [4.60 ms, 11 ms] 3315.85x speedup
Large binary / FullZip / mixed / C1 / S100 / new 13094 ms [8312 ms, 29042 ms] 12652 ms [12557 ms, 13180 ms] 1.03x speedup
Large binary / FullZip / mixed / C1 / S100 / reused 9326 ms [9230 ms, 22094 ms] 1670 ms [1323 ms, 2095 ms] 5.59x speedup
Large binary / FullZip / nonempty / C1 / S100 / new 13540 ms [12452 ms, 33016 ms] 3547 ms [3386 ms, 3925 ms] 3.82x speedup
Large binary / FullZip / nonempty / C1 / S100 / reused 7936 ms [6406 ms, 9119 ms] 289 ms [257 ms, 293 ms] 27.42x speedup
Large binary / FullZip / scalar / C1 / S100 / new 1900 ms [1821 ms, 2212 ms] 1853 ms [1846 ms, 1889 ms] 1.03x speedup
Large binary / FullZip / scalar / C1 / S100 / reused 296 ms [277 ms, 309 ms] 277 ms [271 ms, 308 ms] 1.07x speedup
Small binary / MiniBlock / length / C1 / S100 / new 2277 ms [1882 ms, 3033 ms] 4506 ms [4352 ms, 4952 ms] 1.98x higher
Small binary / MiniBlock / length / C1 / S100 / reused 397 ms [335 ms, 404 ms] 1.83 ms [1.58 ms, 1.92 ms] 217.09x speedup
Fixed binary / FullZip / length / C1 / S100 / new 7937 ms [7840 ms, 16408 ms] 3565 ms [3214 ms, 3627 ms] 2.23x speedup
Fixed binary / FullZip / length / C1 / S100 / reused 6696 ms [4560 ms, 17455 ms] 11 ms [7.73 ms, 14 ms] 605.56x speedup
Integer / MiniBlock / length / C1 / S100 / new 2591 ms [2425 ms, 2881 ms] 5528 ms [5148 ms, 6483 ms] 2.13x higher
Integer / MiniBlock / length / C1 / S100 / reused 853 ms [780 ms, 910 ms] 2.51 ms [1.13 ms, 6.41 ms] 339.13x speedup

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
Scenario Baseline This PR
Large binary / FullZip / count / new 210265768 B / 28 requests 3657 B / 41 requests
Large binary / FullZip / count / reused 210003080 B / 16 requests 0 B / 0 requests
Large binary / FullZip / full / new 210265768 B / 28 requests 210265768 B / 28 requests
Large binary / FullZip / full / reused 210003080 B / 16 requests 210003080 B / 16 requests
Large binary / FullZip / length / new 210265768 B / 28 requests 10953 B / 929 requests
Large binary / FullZip / length / reused 210003080 B / 16 requests 0 B / 0 requests
Large binary / FullZip / mixed / new 212364472 B / 36 requests 2109657 B / 937 requests
Large binary / FullZip / mixed / reused 212101256 B / 20 requests 2098176 B / 4 requests
Large binary / FullZip / nonempty / new 210267080 B / 32 requests 4729 B / 49 requests
Large binary / FullZip / nonempty / reused 210004136 B / 20 requests 1056 B / 4 requests
Large binary / FullZip / scalar / new 263216 B / 12 requests 263216 B / 12 requests
Large binary / FullZip / scalar / reused 1056 B / 4 requests 1056 B / 4 requests
Small binary / MiniBlock / length / new 493600 B / 12 requests 8721 B / 82 requests
Small binary / MiniBlock / length / reused 115280 B / 4 requests 0 B / 0 requests
Fixed binary / FullZip / length / new 233047465 B / 28 requests 3641 B / 41 requests
Fixed binary / FullZip / length / reused 232784777 B / 16 requests 0 B / 0 requests
Integer / MiniBlock / length / new 751876 B / 16 requests 37792 B / 246 requests
Integer / MiniBlock / length / reused 487512 B / 4 requests 0 B / 0 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.

Local scenario / round latency (lower is better) Baseline This PR Benefit
Large binary / full / new 29.90 ms [29.46 ms, 30.54 ms] 29.65 ms [29.29 ms, 30.65 ms] Comparable medians
Large binary / full / reused 16.49 ms [16.08 ms, 17.18 ms] 16.85 ms [15.83 ms, 17.47 ms] 1.02x higher latency
Large binary / length / new 31.51 ms [29.65 ms, 43.41 ms] 9.80 ms [9.52 ms, 9.98 ms] 3.22x speedup
Small binary / length / new 2.16 ms [2.01 ms, 2.61 ms] 2.61 ms [2.50 ms, 3.16 ms] 1.21x higher latency
Integer / length / new 2.91 ms [2.24 ms, 3.48 ms] 4.07 ms [3.83 ms, 4.43 ms] 1.40x higher latency

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.

@github-actions github-actions Bot added A-encoding Encoding, IO, file reader/writer performance labels Nov 5, 2026
@BubbleCal
BubbleCal marked this pull request as ready for review November 5, 2026 14:05

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@lance-gatekeeper lance-gatekeeper Bot left a comment

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.

⚠️ Gate recommendation: approve with a non-blocking risk.

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.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 5, 2026
@BubbleCal
BubbleCal merged commit 0976cc2 into main Nov 5, 2026
49 of 50 checks passed
@BubbleCal
BubbleCal deleted the yang/t200-array-length-structure branch November 5, 2026 15:53
BubbleCal added a commit that referenced this pull request Nov 5, 2026
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.
Xuanwo pushed a commit to lancedb/lancedb that referenced this pull request Nov 6, 2026
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.
Xuanwo pushed a commit that referenced this pull request Nov 20, 2026
…#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)
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 breaking-change K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants