Skip to content

[Variant] Extract unshredded object fields straight from bytes in variant_get - #11506

Closed
cetra3 wants to merge 1 commit into
apache:mainfrom
pydantic:variant-get-field-fast-path
Closed

cetra3 wants to merge 1 commit into
apache:mainfrom
pydantic:variant-get-field-fast-path

Conversation

@cetra3

@cetra3 cetra3 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

  • N/A

Rationale for this change

For a path of field names over unshredded data, variant_get builds a Variant for every row, validates its metadata, value and object headers, and then walks the path through it. Most of that work serves fields that the lookup never reads. Rows that do not contain the requested field do all of it and produce a null.

In a profile of variant_get_unshredded_object_path_262k_rows, per-row Variant construction and validation, per-row column downcasts, and the generic path walk take most of the time. The field lookup itself is a small part.

What changes are included in this PR?

  • A private module, variant_field_lookup, finds a field by a path of names directly in the encoded metadata and value bytes. It reads only the headers it needs and the dictionary names that the binary search probes. It compares names as bytes. Every read is bounds-checked.
  • variant_get uses it when the output type is concrete, the path has only field names, the target has no typed_value, and the metadata and value columns are BinaryView. It builds a Variant only for the value found, and uses the existing row builder to convert it. Rows without the field append null and build nothing.
  • Other inputs keep the existing per-row path. There are no public API changes.

Are these changes tested?

The existing variant_get tests build their input with json_to_variant, which produces BinaryView columns. Thus the tests with field paths and typed output now run through the new path. The new module has unit tests for top-level and nested lookups, missing fields, non-object values, an empty path, agreement with VariantObject::get for every field of a 300-field object, and truncated input.

Benchmarks (variant_kernels, local run, main vs this PR, three alternating runs):

benchmark main this PR change
variant_get_unshredded_object_path_262k_rows 22.21 ms 9.99 ms −55%

Local run on an Apple Silicon laptop. No other variant_kernels benchmark uses a field-name path. On real-world telemetry data with per-row metadata, we measured variant_get on unshredded object fields at 42–55% faster.

Are there any significant user-facing changes?

No. One behavior difference: on the new path, malformed variant bytes produce an error, or a null under safe casting. The existing path panics in Variant::new on malformed bytes.

…iant_get

For a path of field names over unshredded `BinaryView` columns with a concrete
output type, `variant_get` now finds each row's field directly in the encoded
bytes. It builds a `Variant` only for the value it finds, instead of building
and validating a `Variant` for every row and then walking the path through it.
Other inputs keep the existing per-row path.
@cetra3

cetra3 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

run benchmark variant_kernels

env:
BENCH_FILTER: "^(variant_get|shred_variant)"

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: variant_kernels

Sharding factor: 1 (1 workers).

Comparing variant-get-field-fast-path (0f37956) to dfef34e (merge-base) diff

Run configuration
run benchmark variant_kernels
env:
  BENCH_FILTER: ^(variant_get|shred_variant)
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@github-actions github-actions Bot added the parquet-variant parquet-variant* crates label Oct 11, 2026
@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: variant_kernels

Comparing variant-get-field-fast-path (0f37956) to dfef34e (merge-base) diff

Run configuration
run benchmark variant_kernels
env:
  BENCH_FILTER: ^(variant_get|shred_variant)
shards: 1
Details
group                                                                            base                                   changed
-----                                                                            ----                                   -------
shred_variant_partial_object_8k_rows                                             1.01     21.1±0.17ms        ? ?/sec    1.00     20.9±0.13ms        ? ?/sec
shred_variant_unmatched_object_8k_rows                                           1.01     26.5±0.38ms        ? ?/sec    1.00     26.3±0.18ms        ? ?/sec
variant_get_binary_from_string                                                   1.00    481.8±1.14µs        ? ?/sec    1.00    481.1±1.13µs        ? ?/sec
variant_get_binary_from_unshredded_binary                                        1.01    466.2±8.42µs        ? ?/sec    1.00    463.4±3.13µs        ? ?/sec
variant_get_decimal_double_to_decimal128(20,3)_non_finite_8192_safe              1.01    500.9±0.99µs        ? ?/sec    1.00    494.1±0.91µs        ? ?/sec
variant_get_decimal_double_to_decimal128(20,3)_valid_8192_safe                   1.01    515.7±1.89µs        ? ?/sec    1.00    510.9±0.88µs        ? ?/sec
variant_get_decimal_double_to_decimal128(20,3)_valid_8192_strict                 1.01    544.1±2.12µs        ? ?/sec    1.00    537.4±1.32µs        ? ?/sec
variant_get_decimal_double_to_decimal256(40,-2)_scale_down_8192_safe             1.01    918.7±4.23µs        ? ?/sec    1.00    906.6±6.51µs        ? ?/sec
variant_get_decimal_double_to_decimal64(3,0)_precision_overflow_8192_safe        1.00    440.9±0.99µs        ? ?/sec    1.00    438.7±0.80µs        ? ?/sec
variant_get_decimal_float_to_decimal32(7,2)_valid_8192_safe                      1.00    454.6±1.23µs        ? ?/sec    1.00    455.9±1.53µs        ? ?/sec
variant_get_decimal_float_to_decimal32(7,2)_valid_8192_strict                    1.02    509.0±6.74µs        ? ?/sec    1.00    501.0±3.25µs        ? ?/sec
variant_get_decimal_float_to_decimal64(3,0)_precision_overflow_8192_safe         1.00    449.8±1.17µs        ? ?/sec    1.00    451.0±0.83µs        ? ?/sec
variant_get_decimal_int32_to_decimal32(8,0)_precision_overflow_8192_safe         1.00    481.4±0.99µs        ? ?/sec    1.00    483.7±1.01µs        ? ?/sec
variant_get_decimal_int32_to_decimal32(9,0)_valid_8192_safe                      1.00    469.0±1.08µs        ? ?/sec    1.00    470.1±0.68µs        ? ?/sec
variant_get_decimal_int32_to_decimal32(9,0)_valid_8192_strict                    1.01    517.3±6.33µs        ? ?/sec    1.00    509.7±2.50µs        ? ?/sec
variant_get_decimal_int64_to_decimal128(38,2)_scale_up_8192_safe                 1.02    524.9±2.23µs        ? ?/sec    1.00    513.0±2.09µs        ? ?/sec
variant_get_decimal_int64_to_decimal128(38,2)_scale_up_8192_strict               1.03    571.2±3.84µs        ? ?/sec    1.00    555.7±2.39µs        ? ?/sec
variant_get_decimal_int64_to_decimal256(76,-1)_scale_down_8192_safe              1.01    531.5±1.83µs        ? ?/sec    1.00    526.2±1.84µs        ? ?/sec
variant_get_decimal_int64_to_decimal32(9,-1)_scale_before_narrowing_8192_safe    1.01    482.4±0.88µs        ? ?/sec    1.00    478.7±0.89µs        ? ?/sec
variant_get_decimal_int64_to_decimal32(9,-20)_all_zero_8192_safe                 1.00    488.5±0.82µs        ? ?/sec    1.00    486.9±0.88µs        ? ?/sec
variant_get_list_index_all_oob_int64_64_rows                                     1.02  1780.8±30.11ns        ? ?/sec    1.00  1749.5±18.15ns        ? ?/sec
variant_get_list_index_shredded                                                  1.01     45.5±3.43µs        ? ?/sec    1.00     45.1±1.18µs        ? ?/sec
variant_get_list_index_unshredded                                                1.00  1009.9±16.58µs        ? ?/sec    1.00  1005.0±16.44µs        ? ?/sec
variant_get_primitive                                                            1.00    564.0±7.03ns        ? ?/sec    1.01    569.0±9.07ns        ? ?/sec
variant_get_shredded_utf8                                                        1.01    716.4±7.59ns        ? ?/sec    1.00   709.1±10.95ns        ? ?/sec
variant_get_unshredded_object_path_262k_rows                                     1.29     37.1±0.60ms        ? ?/sec    1.00     28.8±1.86ms        ? ?/sec
variant_get_utf8_from_date                                                       1.00    569.2±5.57µs        ? ?/sec    1.00    569.3±5.16µs        ? ?/sec
variant_get_utf8_from_decimal                                                    1.00    474.2±5.84µs        ? ?/sec    1.00    473.6±5.83µs        ? ?/sec
variant_get_utf8_from_float                                                      1.00    446.3±1.17µs        ? ?/sec    1.00    446.9±0.93µs        ? ?/sec
variant_get_utf8_from_int                                                        1.00    446.4±1.32µs        ? ?/sec    1.00    446.6±0.96µs        ? ?/sec
variant_get_utf8_from_list                                                       1.01   651.2±13.70µs        ? ?/sec    1.00   644.0±13.65µs        ? ?/sec
variant_get_utf8_from_map_in_list                                                1.03   684.0±15.41µs        ? ?/sec    1.00   664.9±13.19µs        ? ?/sec
variant_get_utf8_from_time                                                       1.00    783.1±2.66µs        ? ?/sec    1.00    783.2±2.65µs        ? ?/sec
variant_get_utf8_from_timestamp_with_timezone                                    1.00    569.9±2.71µs        ? ?/sec    1.00    570.8±3.07µs        ? ?/sec
variant_get_utf8_from_timestamp_without_timezone                                 1.00    570.4±2.82µs        ? ?/sec    1.00    570.0±2.87µs        ? ?/sec
variant_get_utf8_from_unshredded_string                                          1.01    500.0±7.37µs        ? ?/sec    1.00    495.7±1.20µs        ? ?/sec

Per-runner information
variant_kernels — shard 1/1

Node: gk3-benchmark-cluster-nap-1tnnmms2-d85061fd-7fjk

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

uname:

Linux bench-c6104653077-3285-p2mzz 6.12.94+ #1 SMP Fri Aug 21 08:00:16 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernels
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Resource Usage

base (merge-base)

Metric Value
Wall time 385.1s
Peak memory 349.0 MiB
Avg memory 276.9 MiB
CPU user 381.0s
CPU sys 0.2s
Peak spill 0 B

branch

Metric Value
Wall time 380.1s
Peak memory 445.8 MiB
Avg memory 280.6 MiB
CPU user 377.3s
CPU sys 0.2s
Peak spill 0 B

File an issue against this benchmark runner

@cetra3

cetra3 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

superceded by #11511

@cetra3 cetra3 closed this Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parquet-variant parquet-variant* crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants