Skip to content

perf(encoding): accelerate ByteStreamSplit with SIMD byte transpose - #10905

Merged
Xuanwo merged 1 commit into
mainfrom
xuanwo/perf-bss-simd
Nov 10, 2026
Merged

Xuanwo merged 1 commit into
mainfrom
xuanwo/perf-bss-simd

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Nov 10, 2026

Copy link
Copy Markdown
Member

ByteStreamSplitEncoder and ByteStreamSplitDecompressor previously zero-initialized output buffers with vec![0u8; total_bytes] before overwriting every byte and transposed byte streams with a runtime-strided scalar loop (0..self.bytes_per_value) that could not vectorize into SIMD byte-shuffle instructions.

Write directly into uninitialized Vec<u8> capacity after validating buffer lengths, specialize stream widths 4 (f32) and 8 (f64), and add x86_64 AVX2 and aarch64 NEON byte-transpose kernels with scalar tail handling. On-disk encoding and metadata are unchanged.

Benchmark

End-to-end Lance v2.2 in-memory FileWriter and FileReader full-scan throughput over 4 MiB RecordBatch columns (1,048,576 Float32 values / 524,288 Float64 values), comparing main (5e75eb100b) against d72ea0c39c on AMD EPYC 4585PX (release-with-debug, single pinned core, median across 7 alternating paired rounds):

Workload (Lance v2.2, 4 MiB) main This PR Speedup
Float32 write (compression=lz4, default bss=auto) 2.06 GiB/s (1.90 ms) 5.45 GiB/s (0.72 ms) 2.65x
Float32 full scan (compression=lz4, default bss=auto) 1.87 GiB/s (2.09 ms) 4.48 GiB/s (0.87 ms) 2.39x
Float64 write (compression=lz4, default bss=auto) 1.96 GiB/s (2.00 ms) 4.24 GiB/s (0.92 ms) 2.13x
Float64 full scan (compression=lz4, default bss=auto) 2.37 GiB/s (1.65 ms) 6.41 GiB/s (0.61 ms) 2.72x
Float32 full scan (high-entropy bss=on) 1.82 GiB/s (2.15 ms) 4.34 GiB/s (0.90 ms) 2.35x
Float64 full scan (high-entropy bss=on) 2.33 GiB/s (1.68 ms) 6.03 GiB/s (0.65 ms) 2.65x

@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.

@github-actions github-actions Bot added A-encoding Encoding, IO, file reader/writer performance labels Nov 10, 2026

@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.

The optimized transpose preserves the existing BSS byte layout and chunk metadata. I found no merge-blocking issues.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 10, 2026
@Xuanwo
Xuanwo merged commit d3cc83d into main Nov 10, 2026
41 checks passed
@Xuanwo
Xuanwo deleted the xuanwo/perf-bss-simd branch November 10, 2026 18:07
BubbleCal pushed a commit that referenced this pull request Nov 11, 2026
…element (#10947)

## Summary

Filters can now use the lambda form for per-element predicates on
`list<struct>` columns:

```sql
array_any_match(detections, d -> d.label = 'car' AND d.confidence > 0.9)
```

While parsing the filter, Lance rewrites it to the `any_element` call
from #10901:

```sql
any_element(detections, 'label = ''car'' AND confidence > 0.9')
```

The two forms behave the same. The lambda never reaches DataFusion's
lambda planning, Substrait or execution, so the DataFusion gaps listed
in #10873 don't apply.

This is track 1 of #10873. General lambda support, track 2, still waits
on DataFusion.

## Design

- **Dialect:** `LanceDialect` enables `supports_lambda_functions`.
Without it, `->` parses as the JSON arrow operator, which Lance already
rejects, so no accepted filter changes meaning. `->>` is unaffected.
- **Rewrite:** `Planner::parse_filter` rewrites the parsed SQL before
planning it. `array_any_match` and its alias `any_match` with a
one-parameter lambda become `any_element(list, '<body>')`:
- `d.label`, `d.details.kind` and `d['my field']` become `label`,
`details.kind` and `` `my field` ``.
- The body is printed back as SQL and becomes the predicate literal, so
Lance's own literal handling applies inside it.
- The list argument must be a `list<struct>` column. Its type is checked
against the schema.
- **Clear errors** for anything `any_element` can't express:
- a column outside the element, or a bare `label` without the parameter;
    - the parameter itself (`d IS NOT NULL`);
    - a numeric subscript (`d[1]`);
    - two parameters;
    - a nested lambda;
    - an argument that isn't a `list<struct>`;
- a lambda in any other function, such as `array_filter`, or outside a
function.

## Tests

- **Dialect:** a lambda argument with a bare and a parenthesized
parameter, and that `->>` is not a lambda.
- **Rewrite:** 7 forms, including the alias, nested fields, subscripts,
a double-quoted string, and inside `NOT`, `AND` and another function
call. 9 error cases, each checked for a message that says what to
change.
- **Dataset**, on #10901's fixture:
- three lambda cases: the basic form, the alias with a subscript, and
`NOT` combined with an indexed column. Each is checked against a
reference evaluation with and without the scalar index, and through
`count_rows`.
    - two rejection cases, through the scanner and `count_rows`.

## Docs

A paragraph on the lambda form in the "Filtering on elements of a list
of structs" section of the read and write guide.

Part of #10873.

Lint: `cargo fmt --all`, and `cargo clippy --no-deps -p lance-datafusion
-p lance --features lance-datafusion/substrait --tests -- -D warnings`.
With dependencies included, clippy on arm64 currently fails in
`lance-encoding` (`unreachable_code` in `byte_stream_split.rs`, from
#10905). That code isn't touched here, and x86 CI doesn't hit it.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
BubbleCal pushed a commit that referenced this pull request Nov 12, 2026
… elements (#10950)

## Summary

Adds `listelement`, an experimental built-in scalar index over fields
inside the elements of a `list<struct>` column. It answers `any_element`
filters (#10901) from the index, with every condition on the same
element:

```python
dataset.create_scalar_index(
    "detections",
    IndexConfig(index_type="listelement", parameters={"keys": ["label", "confidence"]}),
)
dataset.to_table(filter="any_element(detections, 'label = ''car'' AND confidence > 0.9')")
```

This is the second part of #10900. The format is specified in #10949,
and the design discussion is #10948.

**Depends on #10949.** This PR carries the identical
`protos/index.proto` change and generated source so that it compiles.
Those changes drop out when this branch is rebased after #10949 merges.

## Design

- **Training:** one entry per element.
- The key is the element's `keys` fields as a tuple, encoded with
Arrow's row format (ascending, nulls first), so the bytes sort like the
tuples.
    - The posting is the row address.
- Entries are sorted with spilling, and an ordinary BTREE is trained
over the `Binary` keys. The index wraps the BTREE the way the JSON index
wraps its target.
- **Search:** `visit_scalar_function` claims `any_element(<indexed
column>, '<literal>')`. The predicate is planned exactly as
`any_element` plans it, then with the tuple planner
(`plan_tuple_predicate`) over the keys.
- **Seeks:** an `=`, `IN` or `IS NULL` prefix, then one range on the
next key, becomes byte-range seeks in the BTREE.
- **Superset and recheck:** conditions the keys can't express, such as a
field that isn't a key, make the answer a superset. The scan then
rechecks it with `any_element`.
- **No first key, no index:** without a condition on the first key, the
index declines.
- **NULLs:** NULL lists, and elements on which the predicate is NULL,
are tracked, so `NOT` is exact.
- **Maintenance:** update encodes the new fragments the same way, then
defers to the BTREE. Remap defers to the BTREE.
- **Row addresses:** in `lance-table`, the index joins the row-address
and eager-remap lists. On stable-row-ID tables, the #10352 writer fence
applies and compaction remaps the index.
- **`lance-datafusion` API:** it exports `ANY_ELEMENT`,
`any_element_predicate` and `plan_element_predicate`, so the index plans
the same expression the scan evaluates. `lance-index` now depends on
`lance-datafusion` as a normal dependency; there's no cycle.

## Fix included

On a stable-row-ID table, `optimize_indices` dropped old entries of a
row-address index outside fragment 0. The generic update arm in
`merge_scalar_indices` only treated the JSON index as storing row
addresses, so it filtered row addresses against row IDs. That arm now
also covers this index. JSON behavior is unchanged.

## Tests

- **Index unit tests** (13):
- same-element trap, every range operator, `IN`, label-only prefix,
recheck;
    - NULL rows for `NOT`;
    - shapes the index declines;
- details round trip, and invalid parameters (no keys, unknown key,
repeated key, nested key type, unknown parameter, non-struct list);
- segment key mismatch, an all-null column, and the spec's encoding
bytes.
- **`lance-table`:** row-address and eager-remap classification.
- **Dataset tests:** #10901's fixture is extended rather than
duplicated.
- Every filter case, plus the edge-row and invalid-predicate tests, runs
with and without the index, checking the plan and whether it rechecks.
- New: declining when the first key isn't constrained; `fast_search`
plus `optimize_indices`; delete plus compaction remap, with and without
stable row IDs.

## Docs

The read and write guide covers creating the index and which filters it
answers, and the scalar indexing guide has a row for it. Both mark it
experimental.

## Not in this PR

- **Training memory:** there's no explicit budget. Like the JSON index,
training uses the default spill pool. At 100M elements the prototype
needed `LANCE_MEM_POOL_SIZE=8GiB`.
- **Merging segments** for distributed builds.
- **Fragment reuse index:** batch row-ID remapping isn't supported. Like
JSON, the index is reported incompatible on stable-row-ID tables that
use a fragment reuse index.

Closes #10900.

This conflicts with #10947 in the dataset scanner tests and the guide.
Whichever merges second will rebase.

Lint: `cargo fmt --all`, and `cargo clippy --no-deps -p lance-datafusion
-p lance-index -p lance-table -p lance --tests --benches --features
lance-datafusion/substrait -- -D warnings`. With dependencies included,
clippy on arm64 currently fails in `lance-encoding` (`unreachable_code`
from #10905), which this PR doesn't touch.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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 K-approved Latest Gatekeeper recommendation permits acceptance. performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants