Repository navigation
variant: optimize variant object path access (79% lower latency) - #10358
friendlymatthew wants to merge 2 commits into
Conversation
|
cc @alamb |
alamb
left a comment
There was a problem hiding this comment.
Looks pretty good overall -- thank you @friendlymatthew -- I had a few suggestions.
| .expect("created struct should be a valid shredded variant") | ||
| } | ||
|
|
||
| fn create_unshredded_object_variant_array(size: usize) -> VariantArray { |
There was a problem hiding this comment.
It would be helpful if you split the change to the benchmark off into a separate PR I can merge it and then use the benchmarking scripts
| builder.append_null()?; | ||
| false // add this to make match arms have the same return type | ||
|
|
||
| if has_path |
There was a problem hiding this comment.
Could you add some comments to explain the rationale for this condition / fast path?
| && target.typed_value_column().is_none() | ||
| && let Some(value_column) = target.value_column() | ||
| { | ||
| let metadata_column = target.metadata_column(); |
There was a problem hiding this comment.
Given that this function is already pretty long, could you please try and refactor some of the logic into smaller documented functions that each do some particular operation?
|
FYI @adriangb -- is this one related to your recent work? |
|
e1afcbb to
16d7788
Compare
|
run benchmark variant_kernels env: |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing friendlymatthew/optimize-variant-object-path-access (16d7788) to 1a6630b (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_get|shred_variant)"BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernels File an issue against this benchmark runner |
|
run benchmark variant_kernels env: |
1 similar comment
|
run benchmark variant_kernels env: |
2 similar comments
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing friendlymatthew/optimize-variant-object-path-access (16d7788) to 1a6630b (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_get|shred_variant)"CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing friendlymatthew/optimize-variant-object-path-access (16d7788) to 1a6630b (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_get|shred_variant)"BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernels File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing friendlymatthew/optimize-variant-object-path-access (16d7788) to 1a6630b (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_get|shred_variant)"BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernels File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_get|shred_variant)"
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernels File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_get|shred_variant)"
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernels File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing friendlymatthew/optimize-variant-object-path-access (16d7788) to 1a6630b (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_get|shred_variant)"CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing friendlymatthew/optimize-variant-object-path-access (16d7788) to 1a6630b (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_get|shred_variant)"CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_get|shred_variant)"
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_get|shred_variant)"
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernels File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_get|shred_variant)"
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_get|shred_variant)"
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
run benchmark variant_validation variant_builder |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing friendlymatthew/optimize-variant-object-path-access (16d7788) to 1a6630b (merge-base) diff Run configurationrun benchmark variant_validationBENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_validation File an issue against this benchmark runner |
|
run benchmark variant_validation variant_builder |
1 similar comment
|
run benchmark variant_validation variant_builder |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_validation
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_validation File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_builder
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_validation
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_validation
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_builder
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing friendlymatthew/optimize-variant-object-path-access (16d7788) to 1a6630b (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_array_builder|batch_json)"BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernels File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_builder
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_builder File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_validation
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing friendlymatthew/optimize-variant-object-path-access (16d7788) to 1a6630b (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_array_builder|batch_json)"BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernels File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing friendlymatthew/optimize-variant-object-path-access (16d7788) to 1a6630b (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_array_builder|batch_json)"BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernels File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_array_builder|batch_json)"
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernels File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_builder
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing friendlymatthew/optimize-variant-object-path-access (16d7788) to 1a6630b (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_array_builder|batch_json)"CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing friendlymatthew/optimize-variant-object-path-access (16d7788) to 1a6630b (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_array_builder|batch_json)"CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing friendlymatthew/optimize-variant-object-path-access (16d7788) to 1a6630b (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_array_builder|batch_json)"CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_array_builder|batch_json)"
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_array_builder|batch_json)"
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernels File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark running (GKE) | trigger CPU Details (lscpu)Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_array_builder|batch_json)"
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"BENCH_COMMAND=cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernels File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_array_builder|batch_json)"
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing 1a6630b (1a6630b) to 1a6630b diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_array_builder|batch_json)"
baseline:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"
changed:
ref: "1a6630bc2c198955a9d24b34ca560dcbb9167a7f"CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
Benchmark summary
Across 39 benchmarks in three suites: one gets much faster, three get about 2% slower, and 35 are flat.
Each number is the ratio of this branch to its merge base. Every job has a paired main-vs-main control job, because several of these benchmarks move by 1 to 5% on identical code. Twelve change jobs and twelve control jobs in total. The PR title says 79%. That number is from the original measurement in July. The correct number for this branch on this runner is 2.89x, which is a 65% decrease in latency. About the three benchmarks that get slowerNone of the three can reach the code this PR changes, and the direct microbenchmarks of the changed functions are flat:
All three benchmarks that move are in Two things I ruled out:
These benchmarks are very sensitive to placement. On my laptop, My suggestion is to take about 2% on three benchmarks this PR does not target, for 2.89x on the one it does. I am happy to look further if you would rather not. The 35 flat benchmarks, and how these runs were made
Two of those need a note, because the ratio on its own is misleading:
Run configuration, on the run benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_get|shred_variant)"run benchmark variant_kernels
env:
BENCH_FILTER: "^(variant_array_builder|batch_json)"run benchmark variant_validation variant_builderA control job pins both sides to the merge base, baseline:
ref: 1a6630bc2c198955a9d24b34ca560dcbb9167a7f
changed:
ref: 1a6630bc2c198955a9d24b34ca560dcbb9167a7fA control job compares two identical binaries. It gives the noise floor and it shows the tilt above, but it cannot separate a code placement effect from a real cost, because placement only differs between different binaries.
|
Add `VariantObject::get_by_field_id` and `Variant::get_object_field_by_id`, which find a field by the numeric field id that a name resolves to in the value's metadata dictionary. The search is logarithmic for a sorted dictionary, because there lexical name order and numeric field id order agree. Add `VariantMetadata::as_bytes`, so that a caller can recognize when two values share one metadata dictionary and cache work derived from it. Co-Authored-By: Adrian Garcia Badaracco <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
A variant object stores its field names as numeric field ids that index into the value's metadata dictionary, so following a named path element means resolving that name to an id. `variant_get` did that per row, which dominates the cost of extracting a path out of a wide object: a lookup by name compares strings, and each candidate name must first be decoded out of the dictionary. Every row of a batch normally shares one dictionary, so resolve the path once and reuse the resolution until a row arrives with a different dictionary. Two rows are taken to share a dictionary when their metadata bytes have the same address and length, which keeps the check independent of dictionary size. Afterwards each row only searches field ids, which is an integer comparison over unaligned loads. A path that fails to resolve is cached too, since no row sharing that dictionary can match it. Decoding the dictionary itself is also hoisted out of the per-row work, for an unshredded column where every row draws its dictionary from one `metadata` buffer. That is worth a further third on top of the resolution caching. `variant_get_unshredded_object_path_262k_rows` improves by 74%, from 28.1ms to 7.38ms. Co-Authored-By: Matthew Kim <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
16d7788 to
3829624
Compare
# Which issue does this PR close? Follow-up to #10357; corrects the benchmark used by #10358. # Rationale for this change The unshredded object fixture has a literal field named `attr.140`, but `VariantPath::try_from("attr.140")` parses it as two nested fields (`attr` then `140`). Since the fixture has no `attr` field, the benchmark returns NULL for every row instead of extracting the intended value. # What changes are included in this PR? Construct the path with `VariantPathElement::field("attr.140")` and assert that every result is `Some(140)` before entering the timed loop. # Are these changes tested? - `cargo bench --offline -p parquet-variant-compute --bench variant_kernels -- variant_get_unshredded_object_path_262k_rows --test` - `cargo fmt --all -- --check` - `git diff --check` # Are there any user-facing changes? No. This only corrects the benchmark workload; previous timings for this benchmark measured missing-path handling.
|
@adriangb @friendlymatthew can you merge main and rerun the bench? |
|
We ran some benchmarks against this PR using arrays where each row has its own metadata dictionary, which is what From what we can see, there are three reasons:
The existing |
# Which issue does this PR close? Related to apache#10358 # Rationale for this change As @cetra3 pointed out in [this comment](apache#10358 (comment)), the existing object-path `variant_get` benchmark shares one metadata dictionary across all rows and misses the regression with separate per-row dictionaries. This PR adds cases covering `json_to_variant` and `VariantArrayBuilder` output, plus a fixed unshared-metadata fixture, in response to that feedback. # What changes are included in this PR? Adds a `variant_get_object_path_metadata` group with three fixture sources: - `json_to_variant`: measures extraction from JSON conversion output. - `variant_array_builder`: inserts fields in reverse order to exercise unsorted metadata. - `per_row_metadata`: explicitly gives each row its own metadata bytes, preserving this case even if the producers later share dictionaries. Each case extracts `attr.140` as `Int32` from 8,192 rows with 300 fields, alternating between two key sets that both contain the target. Fixture creation is outside the timed loop. The producer cases can therefore reflect future improvements to metadata sharing without including conversion time. # Are these changes tested? All three cases pass a benchmark smoke run. Before timing, they assert the output length and extracted values. The fixed per-row fixture also checks that repeated dictionaries occupy distinct byte ranges. The new cases reproduce the regression when comparing apache#10358 at `38296248d0` with its base, `1a41738b79`: | Case | Base | PR apache#10358 | PR time / base time | | --- | ---: | ---: | ---: | | `json_to_variant` | 11.48 ms | 18.44 ms | 1.61× | | `variant_array_builder` | 10.60 ms | 24.28 ms | 2.29× | | `per_row_metadata` | 10.01 ms | 18.60 ms | 1.86× | These are local mean times from paired runs pinned to CPU 4, with 20 samples per case and the same compiler and dependencies. Another benchmark was running concurrently on the host. # Are there any significant user-facing changes? No.
Rationale for this change
Based on benchmark #10357
This PR speeds up field extraction from unshredded variant objects by avoiding repeated field name decoding for every row
Variant object keys are stored as numeric field ids that map to a metadata dictionary.
variant_getcurrently stores a named path by repeatedly mapping those ids back to strings and comparing the strings for each row, even when a batch shares one metadata dictionary. This repeated per-row work dominates when dealing with wide dictionariesThis optimization adds metadata scoped field id lookups, caches parsed metadata, and resolves named path elements to ids once per metadata dictionary before scanning rows. It re-resolves paths when the metadata changes and retains name lookup for unsorted dictionaries