Skip to content

perf(variant): write object headers directly into the value buffer - #11538

Draft
cakeni wants to merge 1 commit into
apache:mainfrom
cakeni:perf/variant-object-header
Draft

cakeni wants to merge 1 commit into
apache:mainfrom
cakeni:perf/variant-object-header

Conversation

@cakeni

@cakeni cakeni commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #7960.

Rationale for this change

Finishing each Variant object allocates a temporary header buffer and splices it into the value buffer. Writing the header directly into its final location removes that allocation and the splice iterator.

What changes are included in this PR?

Grow the existing value buffer, move this object's payload with copy_within, and write its header into the resulting slice. Field ordering, encoded offsets, nested builder rollback, and the wire format are preserved. The implementation uses safe standard-library operations.

Are these changes tested?

A regression test covers nested objects with earlier and later siblings, empty objects, the 255/256 field-count and payload-size boundaries, wider field IDs, and three-byte offsets. Existing builder and interoperability tests exercise the encoded format.

The existing variant_builder benchmarks were run in before/after/after/before order on Windows x64 with Rust 1.99.0, 30 samples, 1 s warm-up, and 3 s measurement. Mean times:

Benchmark Before A → after A Before B → after B
Objects with the same schema 36.642 → 36.190 ms (1.2% lower) 37.704 → 36.181 ms (4.0% lower)
List of same-schema objects 25.544 → 24.215 ms (5.2% lower) 25.704 → 23.989 ms (6.7% lower)
128 fields, validation disabled 21.587 → 20.641 µs (4.4% lower) 21.789 → 20.809 µs (4.5% lower)
128 fields, validation enabled 21.325 → 20.615 µs (3.3% lower) 21.470 → 20.931 µs (2.5% lower)

The runs were made after local test and lint builds finished. These are local desktop measurements, not a general speedup claim.

Are there any significant user-facing changes?

No public API or encoded-format changes.

@github-actions github-actions Bot added parquet-variant parquet-variant* crates enhancement New feature/addition labels Oct 13, 2026
@alamb alamb added the performance Speed or memory optimizations label Oct 16, 2026

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

Seems like listbuilder can get the same treatment. LMK if you can add it here or we should do it in a follow up

@sdf-jkl

sdf-jkl commented Nov 13, 2026

Copy link
Copy Markdown
Member

run benchmark variant_builder

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: variant_builder

Sharding factor: 1 (1 workers).

Comparing perf/variant-object-header (4560e7f) to 72887ed (merge-base) diff

Run configuration
run benchmark variant_builder
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@sdf-jkl

sdf-jkl commented Nov 13, 2026

Copy link
Copy Markdown
Member

@cakeni could you please enable CI on your fork 🙏

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: variant_builder

Comparing perf/variant-object-header (4560e7f) to 72887ed (merge-base) diff

Run configuration
run benchmark variant_builder
shards: 1
Details
group                                       base                                   changed
-----                                       ----                                   -------
bench_extend_metadata_builder               1.00     22.6±0.26ms        ? ?/sec    1.00     22.7±0.21ms        ? ?/sec
bench_object_field_names_reverse_order      1.04     14.9±0.51ms        ? ?/sec    1.00     14.3±0.58ms        ? ?/sec
bench_object_list_partially_same_schema     1.07  1059.4±12.24µs        ? ?/sec    1.00   989.1±10.12µs        ? ?/sec
bench_object_list_same_schema               1.09     21.9±0.53ms        ? ?/sec    1.00     20.0±0.10ms        ? ?/sec
bench_object_list_unknown_schema            1.05     11.0±0.07ms        ? ?/sec    1.00     10.4±0.05ms        ? ?/sec
bench_object_partially_same_schema          1.05      2.7±0.01ms        ? ?/sec    1.00      2.6±0.01ms        ? ?/sec
bench_object_same_schema                    1.06     32.0±0.10ms        ? ?/sec    1.00     30.1±0.10ms        ? ?/sec
bench_object_unknown_schema                 1.04     13.2±0.12ms        ? ?/sec    1.00     12.7±0.02ms        ? ?/sec
iteration/unvalidated_fallible_iteration    1.00      2.7±0.00ms        ? ?/sec    1.02      2.8±0.00ms        ? ?/sec
iteration/validated_iteration               1.00     39.8±0.40µs        ? ?/sec    1.00     39.8±0.42µs        ? ?/sec
object_insert_unique_fields/unvalidated     1.05     24.0±0.16µs  5.1 MElem/sec    1.00     22.8±0.17µs  5.3 MElem/sec
object_insert_unique_fields/validated       1.06     24.1±0.16µs  5.1 MElem/sec    1.00     22.8±0.17µs  5.4 MElem/sec
validation/unvalidated_construction         1.00      4.3±0.07µs        ? ?/sec    1.00      4.3±0.09µs        ? ?/sec
validation/validated_construction           1.00     68.1±0.83µs        ? ?/sec    1.00     68.1±1.46µs        ? ?/sec
validation/validation_cost                  1.01     57.4±0.92µs        ? ?/sec    1.00     57.0±0.90µs        ? ?/sec

Per-runner information
variant_builder — shard 1/1

Node: gk3-benchmark-cluster-nap-f702hydc-2e2e641d-wb7q

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

uname:

Linux bench-c6867663724-5083-vf94k 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_builder
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 155.0s
Peak memory 54.2 MiB
Avg memory 21.5 MiB
CPU user 150.7s
CPU sys 2.2s
Peak spill 0 B

branch

Metric Value
Wall time 165.0s
Peak memory 54.2 MiB
Avg memory 22.1 MiB
CPU user 157.1s
CPU sys 2.1s
Peak spill 0 B

File an issue against this benchmark runner

@alamb
alamb marked this pull request as draft November 24, 2026 21:01
@alamb

alamb commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

converting to draft as we are waiting on the author.

@cakeni please let us know if you are willing to complete this PR (or @sdf-jkl let me know if you want me to take it over / approve a revival of it)

@sdf-jkl

sdf-jkl commented Nov 24, 2026

Copy link
Copy Markdown
Member

@cakeni have been silent on gh for a month 😢

I hope he's doing fine

@alamb

alamb commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Yeah I hope so too -- maybe it was a burst of AI powered contributions. Looks like not much activity recently

Screenshot 2026-11-24 at 4 42 11 PM

@sdf-jkl

sdf-jkl commented Nov 24, 2026

Copy link
Copy Markdown
Member

AI enhanced*

@cakeni

cakeni commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

I’ll keep working on this.

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

enhancement New feature/addition parquet-variant parquet-variant* crates performance Speed or memory optimizations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Variant] Avoiding extra splice in ObjectBuilder::finish if possible

4 participants