Skip to content

perf(variant): read unshredded columns through views in variant_get - #12310

Open
cetra3 wants to merge 3 commits into
apache:mainfrom
pydantic:variant-views-3-get
Open

cetra3 wants to merge 3 commits into
apache:mainfrom
pydantic:variant-views-3-get

Conversation

@cetra3

@cetra3 cetra3 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

For a path over unshredded data, variant_get builds a Variant for every row and then walks the path through it. Building the Variant checks the first and last offsets of the metadata and of each object and list, and each field lookup validates the UTF-8 of the names that it probes. Rows that do not contain the path do all of that and produce a null.

What changes are included in this PR?

  • VariantView::get_path follows a path of field names and list indexes through the views added in feat(variant): add header-only views of encoded variant bytes #12309.
  • variant_get reads a column that has no typed_value through it, for field and index paths and for typed and Variant output. A row reads only the headers and names along the path, and decodes only the value that it finds.
  • A crate-private BinaryColumn resolves the array type of the metadata and value columns once, not on every row.
  • Following on from VariantObjectHeader in feat(variant): add header-only views of encoded variant bytes #12309, VariantMetadataHeader and VariantListHeader now hold the header byte and decode it in their accessors. Every row builds a metadata view and every list row builds a list view, and one byte is cheaper to build and copy than the decoded fields. VariantListHeader::new cannot fail, and the now unused OffsetSizeBytes::try_new is removed.

The gain comes from skipping the per-row Variant construction and the UTF-8 validation of probed names. A scalar result also never reads the metadata dictionary.

Are these changes tested?

The existing variant_get tests cover the new path, because their unshredded input now takes it. VariantView::get_path has a test that compares it with Variant::get_path.

Benchmarks (local run, x86_64 Linux, against #12309 before it merged):

benchmark #12309 this PR change
variant_get_binary_from_string 316.95 µs 207.79 µs −34%
variant_get_binary_from_unshredded_binary 264.24 µs 194.71 µs −26%
variant_get_list_index_all_oob_int64_64_rows 421.86 ns 418.12 ns −1%
variant_get_list_index_shredded 26.80 µs 25.72 µs −4%
variant_get_list_index_unshredded 576.96 µs 308.11 µs −47%
variant_get_shredded_utf8 342.91 ns 341.04 ns −1%
variant_get_unshredded_object_path_262k_rows 22.79 ms 14.98 ms −34%
variant_get_utf8_from_date 386.90 µs 306.39 µs −21%
variant_get_utf8_from_decimal 265.38 µs 186.75 µs −30%
variant_get_utf8_from_float 255.41 µs 176.07 µs −31%
variant_get_utf8_from_int 256.21 µs 179.43 µs −30%
variant_get_utf8_from_list 369.64 µs 323.23 µs −13%
variant_get_utf8_from_map_in_list 367.95 µs 328.31 µs −11%
variant_get_utf8_from_time 452.92 µs 370.30 µs −18%
variant_get_utf8_from_timestamp_with_timezone 320.17 µs 241.92 µs −24%
variant_get_utf8_from_timestamp_without_timezone 318.81 µs 243.21 µs −24%
variant_get_utf8_from_unshredded_string 321.26 µs 214.52 µs −33%

The shredded benchmarks (variant_get_shredded_utf8, variant_get_list_index_shredded, variant_get_list_index_all_oob_int64_64_rows) do not take the new path.

Are there any user-facing changes?

New public API in parquet-variant: VariantView::get_path.

On malformed variant bytes, variant_get on an unshredded column returns an error, or a null under safe casting. Before, this path could panic.

🤖 Generated with Claude Code

https://claude.ai/code/session_01USkuh43UDwSoij2az8NwbM

Comment thread parquet-variant/src/variant/view.rs Outdated
///
/// ```
/// # use parquet_variant::{Variant, VariantBuilder, VariantMetadataView, VariantView};
/// # use parquet_variant::{Variant, VariantBuilder, VariantMetadataView, VariantPath, VariantView};

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.

maybe adding a new example that has paths would be clearer than moding the existing example?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 0bdfda4: the type-level example is back to the step-by-step get_field / get_index version, and get_path has its own example, including a path that does not exist.

@cetra3
cetra3 force-pushed the variant-views-3-get branch 2 times, most recently from 78891e4 to fc232ec Compare November 24, 2026 03:46
adriangb added a commit to pydantic/arrow-rs that referenced this pull request Nov 26, 2026
@cetra3
cetra3 force-pushed the variant-views-3-get branch 2 times, most recently from aea8314 to fdec92b Compare November 27, 2026 07:16
@cetra3

cetra3 commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

run benchmark variant_kernels

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

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: variant_kernels

Sharding factor: 1 (1 workers).

Comparing variant-views-3-get (fdec92b) to e6977de (merge-base) diff

Run configuration
run benchmark variant_kernels
env:
  BENCH_FILTER: ^(variant_get|unshred_variant)
shards: 1
Trigger comment
run benchmark variant_kernels

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

Results will be posted when all workers finish.


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: variant_kernels

Comparing variant-views-3-get (fdec92b) to e6977de (merge-base) diff

Run configuration
run benchmark variant_kernels
env:
  BENCH_FILTER: ^(variant_get|unshred_variant)
shards: 1
Trigger comment
run benchmark variant_kernels

env:
  BENCH_FILTER: "^(variant_get|unshred_variant)"
Details
group                                                                            base                                   changed
-----                                                                            ----                                   -------
unshred_variant_list                                                             1.04     10.0±0.07ms        ? ?/sec    1.00      9.6±0.04ms        ? ?/sec
unshred_variant_list_of_objects                                                  1.01     21.5±0.15ms        ? ?/sec    1.00     21.3±0.12ms        ? ?/sec
unshred_variant_nested_fallback                                                  1.04    158.9±0.76ms        ? ?/sec    1.00    152.7±0.21ms        ? ?/sec
unshred_variant_object                                                           1.04      5.5±0.07ms        ? ?/sec    1.00      5.3±0.04ms        ? ?/sec
unshred_variant_partial_object                                                   1.06     43.8±0.18ms        ? ?/sec    1.00     41.3±0.15ms        ? ?/sec
unshred_variant_partial_object_unsorted_metadata                                 1.36   232.5±26.37ms        ? ?/sec    1.00    171.4±1.62ms        ? ?/sec
unshred_variant_primitive                                                        1.08    442.3±5.84µs        ? ?/sec    1.00    407.8±4.68µs        ? ?/sec
variant_get_binary_from_string                                                   1.19    474.7±4.34µs        ? ?/sec    1.00    399.1±2.30µs        ? ?/sec
variant_get_binary_from_unshredded_binary                                        1.15    454.9±8.86µs        ? ?/sec    1.00   394.2±10.20µs        ? ?/sec
variant_get_decimal_double_to_decimal128(20,3)_non_finite_8192_safe              1.16    503.1±5.77µs        ? ?/sec    1.00    434.9±6.57µs        ? ?/sec
variant_get_decimal_double_to_decimal128(20,3)_valid_8192_safe                   1.22    523.6±5.60µs        ? ?/sec    1.00    429.2±3.09µs        ? ?/sec
variant_get_decimal_double_to_decimal128(20,3)_valid_8192_strict                 1.25    533.5±6.13µs        ? ?/sec    1.00    428.5±3.04µs        ? ?/sec
variant_get_decimal_double_to_decimal256(40,-2)_scale_down_8192_safe             1.09  1041.6±23.88µs        ? ?/sec    1.00    955.0±4.18µs        ? ?/sec
variant_get_decimal_double_to_decimal64(3,0)_precision_overflow_8192_safe        1.27    494.3±3.57µs        ? ?/sec    1.00    389.4±2.98µs        ? ?/sec
variant_get_decimal_float_to_decimal32(7,2)_valid_8192_safe                      1.30    462.7±3.30µs        ? ?/sec    1.00    355.6±2.50µs        ? ?/sec
variant_get_decimal_float_to_decimal32(7,2)_valid_8192_strict                    1.33    473.4±4.92µs        ? ?/sec    1.00    355.6±2.59µs        ? ?/sec
variant_get_decimal_float_to_decimal64(3,0)_precision_overflow_8192_safe         1.24    498.6±5.47µs        ? ?/sec    1.00    401.7±3.22µs        ? ?/sec
variant_get_decimal_int32_to_decimal32(8,0)_precision_overflow_8192_safe         1.24    470.7±4.23µs        ? ?/sec    1.00    378.6±3.10µs        ? ?/sec
variant_get_decimal_int32_to_decimal32(9,0)_valid_8192_safe                      1.27    458.3±4.34µs        ? ?/sec    1.00    361.8±2.66µs        ? ?/sec
variant_get_decimal_int32_to_decimal32(9,0)_valid_8192_strict                    1.30    470.5±5.83µs        ? ?/sec    1.00    361.7±2.53µs        ? ?/sec
variant_get_decimal_int64_to_decimal128(38,2)_scale_up_8192_safe                 1.18    492.4±6.44µs        ? ?/sec    1.00    416.4±7.25µs        ? ?/sec
variant_get_decimal_int64_to_decimal128(38,2)_scale_up_8192_strict               1.20    499.7±5.96µs        ? ?/sec    1.00    415.8±6.80µs        ? ?/sec
variant_get_decimal_int64_to_decimal256(76,-1)_scale_down_8192_safe              1.12    502.0±5.07µs        ? ?/sec    1.00    447.5±6.26µs        ? ?/sec
variant_get_decimal_int64_to_decimal32(9,-1)_scale_before_narrowing_8192_safe    1.25    474.0±3.71µs        ? ?/sec    1.00    380.6±2.34µs        ? ?/sec
variant_get_decimal_int64_to_decimal32(9,-20)_all_zero_8192_safe                 1.27    456.2±4.07µs        ? ?/sec    1.00    360.0±2.78µs        ? ?/sec
variant_get_decimal_short_string_to_decimal256(40,-2)_scale_down_8192_safe       1.18    571.6±1.43µs        ? ?/sec    1.00    483.1±6.11µs        ? ?/sec
variant_get_decimal_short_string_to_decimal256(76,2)_wide_8192_safe              1.11    940.7±3.05µs        ? ?/sec    1.00    850.5±4.16µs        ? ?/sec
variant_get_decimal_short_string_to_decimal32(7,2)_valid_8192_safe               1.26    530.2±2.05µs        ? ?/sec    1.00    421.7±5.59µs        ? ?/sec
variant_get_decimal_short_string_to_decimal32(7,2)_valid_8192_strict             1.31    550.9±2.28µs        ? ?/sec    1.00    421.9±5.62µs        ? ?/sec
variant_get_decimal_string_to_decimal128(38,3)_long_8192_safe                    1.09   1099.5±3.54µs        ? ?/sec    1.00   1009.6±9.56µs        ? ?/sec
variant_get_decimal_string_to_decimal128(38,3)_long_8192_strict                  1.12   1131.5±2.64µs        ? ?/sec    1.00   1009.6±9.22µs        ? ?/sec
variant_get_list_index_all_oob_int64_64_rows                                     1.01    874.3±9.69ns        ? ?/sec    1.00    865.7±9.51ns        ? ?/sec
variant_get_list_index_shredded                                                  1.00     46.2±1.34µs        ? ?/sec    1.00     46.2±1.29µs        ? ?/sec
variant_get_list_index_unshredded                                                1.49    996.9±4.12µs        ? ?/sec    1.00    670.9±7.04µs        ? ?/sec
variant_get_object_path_metadata/json_to_variant                                 1.46      2.8±0.04ms        ? ?/sec    1.00  1922.0±44.11µs        ? ?/sec
variant_get_object_path_metadata/per_row_metadata                                1.43      2.6±0.02ms        ? ?/sec    1.00  1854.3±44.65µs        ? ?/sec
variant_get_object_path_metadata/variant_array_builder                           1.43      2.6±0.03ms        ? ?/sec    1.00  1853.5±43.11µs        ? ?/sec
variant_get_primitive                                                            1.00    544.1±4.78ns        ? ?/sec    1.00    545.3±2.70ns        ? ?/sec
variant_get_shredded_utf8                                                        1.00    712.5±3.78ns        ? ?/sec    1.02    724.1±4.96ns        ? ?/sec
variant_get_unshredded_object_path_262k_rows                                     1.07     35.8±0.46ms        ? ?/sec    1.00     33.5±0.23ms        ? ?/sec
variant_get_utf8_from_date                                                       1.22    558.1±1.11µs        ? ?/sec    1.00    458.9±8.94µs        ? ?/sec
variant_get_utf8_from_decimal                                                    1.15    462.4±8.97µs        ? ?/sec    1.00    402.8±4.44µs        ? ?/sec
variant_get_utf8_from_float                                                      1.21    436.8±5.40µs        ? ?/sec    1.00    362.0±3.47µs        ? ?/sec
variant_get_utf8_from_int                                                        1.20    436.3±5.66µs        ? ?/sec    1.00    363.1±3.28µs        ? ?/sec
variant_get_utf8_from_list                                                       1.00    601.7±3.20µs        ? ?/sec    1.15   689.4±20.45µs        ? ?/sec
variant_get_utf8_from_map_in_list                                                1.00    618.4±5.19µs        ? ?/sec    1.15   710.9±21.97µs        ? ?/sec
variant_get_utf8_from_time                                                       1.20    753.1±2.41µs        ? ?/sec    1.00    628.6±2.13µs        ? ?/sec
variant_get_utf8_from_timestamp_with_timezone                                    1.26    550.9±2.71µs        ? ?/sec    1.00    437.7±2.96µs        ? ?/sec
variant_get_utf8_from_timestamp_without_timezone                                 1.26    550.8±2.49µs        ? ?/sec    1.00    437.5±2.27µs        ? ?/sec
variant_get_utf8_from_unshredded_string                                          1.22    486.2±6.73µs        ? ?/sec    1.00    398.2±6.92µs        ? ?/sec

Per-runner information
variant_kernels — shard 1/1

Node: gk3-benchmark-cluster-nap-r75scce3-df3e8234-njrs

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

uname:

Linux bench-c7214034022-5791-dk66m 6.12.105+ #1 SMP Sat Sep 19 07:55:25 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 575.1s
Peak memory 429.8 MiB
Avg memory 254.7 MiB
CPU user 568.2s
CPU sys 0.2s
Peak spill 0 B

branch

Metric Value
Wall time 565.1s
Peak memory 447.3 MiB
Avg memory 256.1 MiB
CPU user 560.5s
CPU sys 0.2s
Peak spill 0 B

File an issue against this benchmark runner

`variant_get` reads each row of an unshredded column through
`VariantView::get_path`. A row reads only the headers and field names
along the path, and decodes only the value that it finds.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@cetra3
cetra3 force-pushed the variant-views-3-get branch from fdec92b to 71b4a58 Compare November 29, 2026 23:38
@cetra3
cetra3 marked this pull request as ready for review November 29, 2026 23:50
@cetra3

cetra3 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

run benchmark variant_kernels

env:
BENCH_FILTER: "^variant_get_utf8_from_(list|map_in_list)$"

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: variant_kernels

Sharding factor: 1 (1 workers).

Comparing variant-views-3-get (0bdfda4) to 3f109cd (merge-base) diff

Run configuration
run benchmark variant_kernels
env:
  BENCH_FILTER: ^variant_get_utf8_from_(list|map_in_list)$
shards: 1
Trigger comment
run benchmark variant_kernels

env:
  BENCH_FILTER: "^variant_get_utf8_from_(list|map_in_list)$"

Results will be posted when all workers finish.


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: variant_kernels

Comparing variant-views-3-get (0bdfda4) to 3f109cd (merge-base) diff

Run configuration
run benchmark variant_kernels
env:
  BENCH_FILTER: ^variant_get_utf8_from_(list|map_in_list)$
shards: 1
Trigger comment
run benchmark variant_kernels

env:
  BENCH_FILTER: "^variant_get_utf8_from_(list|map_in_list)$"
Details
group                                base                                   changed
-----                                ----                                   -------
variant_get_utf8_from_list           1.00    615.5±4.84µs        ? ?/sec    1.12   691.7±21.93µs        ? ?/sec
variant_get_utf8_from_map_in_list    1.00    627.9±4.28µs        ? ?/sec    1.14   715.0±20.31µs        ? ?/sec

Per-runner information
variant_kernels — shard 1/1

Node: gk3-benchmark-cluster-nap-8jswyi8a-b1859a01-gcpt

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

uname:

Linux bench-c7264931825-5841-75977 6.12.105+ #1 SMP Sat Sep 19 07:55:25 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 30.0s
Peak memory 374.7 MiB
Avg memory 306.2 MiB
CPU user 26.5s
CPU sys 0.2s
Peak spill 0 B

branch

Metric Value
Wall time 35.0s
Peak memory 374.8 MiB
Avg memory 296.4 MiB
CPU user 28.9s
CPU sys 0.2s
Peak spill 0 B

File an issue against this benchmark runner

`VariantMetadataHeader` and `VariantListHeader` hold the header byte and
decode it in their accessors, as `VariantObjectHeader` does. Every row
of an unshredded column builds a metadata view, and every list row
builds a list view, so both are copied often, and one byte is cheaper to
build and copy than the decoded fields.

`VariantMetadataHeader::try_new` keeps the version check, its only
error. `VariantListHeader::new` is infallible, because every two-bit
offset size is valid. `OffsetSizeBytes::try_new` lost its last callers
and is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01USkuh43UDwSoij2az8NwbM
@cetra3

cetra3 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

run benchmark variant_kernels

env:
BENCH_FILTER: "^variant_get_utf8_from_(list|map_in_list)$"

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: variant_kernels

Sharding factor: 1 (1 workers).

Comparing variant-views-3-get (b5c17dc) to 3f109cd (merge-base) diff

Run configuration
run benchmark variant_kernels
env:
  BENCH_FILTER: ^variant_get_utf8_from_(list|map_in_list)$
shards: 1
Trigger comment
run benchmark variant_kernels

env:
  BENCH_FILTER: "^variant_get_utf8_from_(list|map_in_list)$"

Results will be posted when all workers finish.


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: variant_kernels

Comparing variant-views-3-get (b5c17dc) to 3f109cd (merge-base) diff

Run configuration
run benchmark variant_kernels
env:
  BENCH_FILTER: ^variant_get_utf8_from_(list|map_in_list)$
shards: 1
Trigger comment
run benchmark variant_kernels

env:
  BENCH_FILTER: "^variant_get_utf8_from_(list|map_in_list)$"
Details
group                                base                                   changed
-----                                ----                                   -------
variant_get_utf8_from_list           1.05    617.5±3.94µs        ? ?/sec    1.00   587.8±12.83µs        ? ?/sec
variant_get_utf8_from_map_in_list    1.02    626.5±4.68µs        ? ?/sec    1.00    616.3±8.08µs        ? ?/sec

Per-runner information
variant_kernels — shard 1/1

Node: gk3-benchmark-cluster-nap-11jkhbhj-434a965e-s885

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

uname:

Linux bench-c7265227107-5842-pdnnd 6.12.105+ #1 SMP Sat Sep 19 07:55:25 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 30.0s
Peak memory 374.7 MiB
Avg memory 296.6 MiB
CPU user 25.7s
CPU sys 0.2s
Peak spill 0 B

branch

Metric Value
Wall time 30.0s
Peak memory 374.7 MiB
Avg memory 294.3 MiB
CPU user 24.9s
CPU sys 0.1s
Peak spill 0 B

File an issue against this benchmark runner

@cetra3

cetra3 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Sorry about the benchmark spam for anyone that has been subscribed. There was a regression in a couple of the benchmarks on ARM that weren't showing up locally, and I had to get to the bottom of it. Both of which look like they're fixed as part of b5c17dc So we're back to speed wins across the board.

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

Looks (really) nice to me. Thank you @cetra3

FYI @sdf-jkl and @klion26


/// Follows `path` from this value, or returns `None` if a step does not exist.
///
/// A [`VariantPathElement::ListElement`] step does not exist, as in [`Variant::get_path`].

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.

I don't understand this sentence. Maybe an example would help (is it saying this function doesn't follow list access like [0])?

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.

If it doesn't support lists, is that something that is added in a follow on PR?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ListElement is the [*] wildcard, not an index. Index steps like [0] are followed (the example below reads scores[1]). [*] matches nothing here, same as Variant::get_path, and variant_get rejects it before it gets this far. Maybe the doc could say that directly:

Suggested change
/// A [`VariantPathElement::ListElement`] step does not exist, as in [`Variant::get_path`].
/// Index steps such as `[0]` are followed. A `[*]` step ([`VariantPathElement::ListElement`])
/// matches nothing and returns `None`, as in [`Variant::get_path`].

So I don't think a follow-up is needed. [*] only makes sense when building shredding schemas (ShreddedSchemaBuilder), and Spark's variant_get path grammar has keys and indexes only, no wildcard.

}

impl OffsetSizeBytes {
/// Build from the `offset_size_minus_one` bits (see spec).

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.

So the point is that the error handling takes too much space / messes up inlining?

I was wondering if removing this somehow removed required validation, but I think given it is only looking at 2 bits there are only 4 possible values, so that should be ok

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No validation was dropped here. Both old callers of try_new already passed only 2 bits (header_byte >> 6 for metadata, value_header & 0x03 for lists), so its error branch could never run, and from_bits masks the same way.

It became dead code once the headers store the raw byte, like VariantObjectHeader in #12309. The description gives the reason for that: one byte is cheaper to build and copy than the decoded fields.

@sdf-jkl sdf-jkl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @cetra3

} else {
as_field.map(|f| f.data_type())
};
if target.typed_value_column().is_none() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With this early return, every non-empty path goes to get_path_from_bytes: the only caller that passes one is the NotShredded step, and its target has no typed_value. That allows two follow-on changes:

  1. The loop below now always gets an empty path, so VariantPathRowBuilder, the WithPath variant and the path parameter of make_variant_to_arrow_row_builder are unreachable.
  2. The unshred_variant call above can move into the empty-path return. Today an explicit Variant output (as_type with the VariantType extension, which is what datafusion-variant passes) unshreds the NotShredded target before get_path_from_bytes reads the same bytes. When some rows have a null leftover value, unshred_variant falls back to its row loop and validates and re-encodes every row first.

Together that is +7/-61:

diff
diff --git a/parquet-variant-compute/src/variant_get.rs b/parquet-variant-compute/src/variant_get.rs
index 4fb2faf4b9..9fe5b44a4a 100644
--- a/parquet-variant-compute/src/variant_get.rs
+++ b/parquet-variant-compute/src/variant_get.rs
@@ -209,7 +209,6 @@ fn get_path_from_bytes(
 ) -> Result<ArrayRef> {
     let mut builder = make_variant_to_arrow_row_builder(
         target.metadata_column(),
-        VariantPath::default(),
         as_type,
         cast_options,
         target.len(),
@@ -287,20 +286,8 @@ fn shredded_get_path(
                 ));
             }
 
-            // Collapse any shredding back to binary. Only the `NotShredded` step below passes a
-            // non-empty `path`, and there `target` is already a plain `value` column (no
-            // `typed_value`) -- so `unshred_variant` hits its clone fast-path, with nothing deeper
-            // to shred. The builder then walks any remaining path per-row, emitting variant output
-            // because `as_type` is `None`.
-            let target = if requested_variant {
-                unshred_variant(&target)?
-            } else {
-                target
-            };
-
-            // Path exhausted, variant requested: return the target directly.
             if requested_variant && path.is_empty() {
-                return Ok(ArrayRef::from(target));
+                return Ok(ArrayRef::from(unshred_variant(&target)?));
             }
 
             let as_type = if requested_variant {
@@ -311,9 +298,11 @@ fn shredded_get_path(
             if target.typed_value_column().is_none() {
                 return get_path_from_bytes(&target, &path, as_type, cast_options);
             }
+            // Only the `NotShredded` step passes a non-empty `path`, and its target has no
+            // `typed_value`.
+            debug_assert!(path.is_empty() && !requested_variant);
             let mut builder = make_variant_to_arrow_row_builder(
                 target.metadata_column(),
-                path,
                 as_type,
                 cast_options,
                 target.len(),
diff --git a/parquet-variant-compute/src/variant_to_arrow.rs b/parquet-variant-compute/src/variant_to_arrow.rs
index 52c3956403..59c35fd876 100644
--- a/parquet-variant-compute/src/variant_to_arrow.rs
+++ b/parquet-variant-compute/src/variant_to_arrow.rs
@@ -25,7 +25,7 @@ use arrow::compute::{CastOptions, DecimalCast, cast_with_options};
 use arrow::datatypes::{self, DataType, DecimalType};
 use arrow::error::{ArrowError, Result};
 use arrow_schema::{FieldRef, Fields, TimeUnit, UnionFields, UnionMode};
-use parquet_variant::{Variant, VariantPath};
+use parquet_variant::Variant;
 use std::sync::Arc;
 
 /// Builder for converting variant values into strongly typed Arrow arrays.
@@ -40,9 +40,6 @@ pub(crate) enum VariantToArrowRowBuilder<'a> {
     Map(MapVariantToArrowRowBuilder<'a>),
     Encoded(EncodedVariantToArrowRowBuilder<'a>),
     BinaryVariant(VariantToBinaryVariantArrowRowBuilder),
-
-    // Path extraction wrapper - contains a boxed enum for any of the above
-    WithPath(VariantPathRowBuilder<'a>),
 }
 
 impl VariantToArrowRowBuilder<'_> {
@@ -56,7 +53,6 @@ impl VariantToArrowRowBuilder<'_> {
             Map(b) => b.append_null(),
             Encoded(b) => b.append_null(),
             BinaryVariant(b) => b.append_null(),
-            WithPath(path_builder) => path_builder.append_null(),
         }
     }
 
@@ -70,7 +66,6 @@ impl VariantToArrowRowBuilder<'_> {
             Map(b) => b.append_value(&value),
             Encoded(b) => b.append_value(value),
             BinaryVariant(b) => b.append_value(value),
-            WithPath(path_builder) => path_builder.append_value(value),
         }
     }
 
@@ -84,7 +79,6 @@ impl VariantToArrowRowBuilder<'_> {
             Map(b) => b.finish(),
             Encoded(b) => b.finish(),
             BinaryVariant(b) => b.finish(),
-            WithPath(path_builder) => path_builder.finish(),
         }
     }
 }
@@ -162,14 +156,13 @@ fn make_typed_variant_to_arrow_row_builder<'a>(
 
 pub(crate) fn make_variant_to_arrow_row_builder<'a>(
     metadata: &ArrayRef,
-    path: VariantPath<'a>,
     data_type: Option<&'a DataType>,
     cast_options: &'a CastOptions,
     capacity: usize,
 ) -> Result<VariantToArrowRowBuilder<'a>> {
     use VariantToArrowRowBuilder::*;
 
-    let mut builder = match data_type {
+    Ok(match data_type {
         // If no data type was requested, build an unshredded VariantArray.
         None => BinaryVariant(VariantToBinaryVariantArrowRowBuilder::new(
             metadata.clone(),
@@ -181,17 +174,7 @@ pub(crate) fn make_variant_to_arrow_row_builder<'a>(
             capacity,
             VariantCastMode::Get,
         )?,
-    };
-
-    // Wrap with path extraction if needed
-    if !path.is_empty() {
-        builder = WithPath(VariantPathRowBuilder {
-            builder: Box::new(builder),
-            path,
-        })
-    }
-
-    Ok(builder)
+    })
 }
 
 /// Builder for converting primitive variant values to Arrow arrays. It is used by both
@@ -1168,32 +1151,6 @@ impl<'a> ArrayVariantToArrowRowBuilder<'a> {
     }
 }
 
-/// A thin wrapper whose only job is to extract a specific path from a variant value and pass the
-/// result to a nested builder.
-pub(crate) struct VariantPathRowBuilder<'a> {
-    builder: Box<VariantToArrowRowBuilder<'a>>,
-    path: VariantPath<'a>,
-}
-
-impl VariantPathRowBuilder<'_> {
-    fn append_null(&mut self) -> Result<()> {
-        self.builder.append_null()
-    }
-
-    fn append_value(&mut self, value: Variant<'_, '_>) -> Result<bool> {
-        if let Some(v) = value.get_path(&self.path) {
-            self.builder.append_value(v)
-        } else {
-            self.builder.append_null()?;
-            Ok(false)
-        }
-    }
-
-    fn finish(self) -> Result<ArrayRef> {
-        self.builder.finish()
-    }
-}
-
 macro_rules! define_variant_to_primitive_builder {
     (struct $name:ident<$lifetime:lifetime $(, $generic:ident: $bound:path )?>
     |$array_param:ident $(, $field:ident: $field_type:ty)?| -> $builder_name:ident $(< $array_type:ty >)? { $init_expr: expr },

The crate tests pass, and the output matches this PR on everything I tried (unshredded, sliced, dictionary metadata, and partially shredded objects, for typed, None and explicit Variant outputs, safe and strict). On 8192 partially shredded objects where half the rows have nothing left over, variant_get of a leftover field with an explicit Variant output went from about 2.6 ms to 0.6 ms locally, the same as with as_type: None. No existing benchmark covers that case, so I can add one in a separate PR.

One side effect: on that route, malformed bytes outside the path no longer raise an error in strict mode, because unshred_variant no longer validates the whole row. That matches the as_type: None route and #12513.

}
}

/// A binary-like column whose array type is resolved once, not on every row.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: only BinaryView is resolved once here. Binary, LargeBinary and dictionary or run-end metadata still go through binary_array_value on every row.

Suggested change
/// A binary-like column whose array type is resolved once, not on every row.
/// A binary-like column that resolves `BinaryView` once and other array types on every row.


/// Follows `path` from this value, or returns `None` if a step does not exist.
///
/// A [`VariantPathElement::ListElement`] step does not exist, as in [`Variant::get_path`].

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ListElement is the [*] wildcard, not an index. Index steps like [0] are followed (the example below reads scores[1]). [*] matches nothing here, same as Variant::get_path, and variant_get rejects it before it gets this far. Maybe the doc could say that directly:

Suggested change
/// A [`VariantPathElement::ListElement`] step does not exist, as in [`Variant::get_path`].
/// Index steps such as `[0]` are followed. A `[*]` step ([`VariantPathElement::ListElement`])
/// matches nothing and returns `None`, as in [`Variant::get_path`].

So I don't think a follow-up is needed. [*] only makes sense when building shredding schemas (ShreddedSchemaBuilder), and Spark's variant_get path grammar has keys and indexes only, no wildcard.

}

impl OffsetSizeBytes {
/// Build from the `offset_size_minus_one` bits (see spec).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No validation was dropped here. Both old callers of try_new already passed only 2 bits (header_byte >> 6 for metadata, value_header & 0x03 for lists), so its error branch could never run, and from_bits masks the same way.

It became dead code once the headers store the raw byte, like VariantObjectHeader in #12309. The description gives the reason for that: one byte is cheaper to build and copy than the decoded fields.

@klion26 klion26 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks for this improvment

// A row with neither `value` nor `typed_value` is `Variant::Null`, which has no fields.
let Some(value) = value.value(i) else {
match path.is_empty() {
true => builder.append_value(Variant::Null).map(drop)?,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do we need to call map(drop) here?

This branch has not been deployed

No deployments
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.

5 participants