Repository navigation
Conversation
|
run benchmark variant_kernels env: |
|
run benchmark variant_kernels env: resources: |
|
run benchmark variant_validation |
|
🤖 Benchmark starting (GKE) | trigger Target: variant_kernels Sharding factor: 1 (1 workers). Comparing variant-typestate-views (340f702) to 4c67abc (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: ^(variant_get|shred_variant)
resources:
arch: amd64
shards: 1
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
🤖 Benchmark starting (GKE) | trigger Target: variant_kernels Sharding factor: 1 (1 workers). Comparing variant-typestate-views (340f702) to 4c67abc (merge-base) diff Run configurationrun 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 |
|
🤖 Benchmark starting (GKE) | trigger Target: variant_validation Sharding factor: 1 (1 workers). Comparing variant-typestate-views (340f702) to 4c67abc (merge-base) diff Run configurationrun benchmark variant_validation
shards: 1
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Target: variant_validation Comparing variant-typestate-views (340f702) to 4c67abc (merge-base) diff Run configurationrun benchmark variant_validation
shards: 1
DetailsPer-runner informationvariant_validation — shard 1/1Node: gk3-benchmark-cluster-nap-1fiesfzt-fd3af563-2trb Instance: c4a-highcpu-48 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_validationCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Target: variant_kernels Comparing variant-typestate-views (340f702) to 4c67abc (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: ^(variant_get|shred_variant)
resources:
arch: amd64
shards: 1
DetailsPer-runner informationvariant_kernels — shard 1/1Node: gk3-benchmark-cluster-nap-9vkbev77-575f51ab-dm7t Instance: c4-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernelsCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Target: variant_kernels Comparing variant-typestate-views (340f702) to 4c67abc (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: ^(variant_get|shred_variant)
shards: 1
DetailsPer-runner informationvariant_kernels — shard 1/1Node: gk3-benchmark-cluster-nap-gidh403n-a9885889-hsc8 Instance: c4a-highcpu-48 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernelsCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
run benchmark variant_validation |
|
🤖 Benchmark starting (GKE) | trigger Target: variant_validation Sharding factor: 1 (1 workers). Comparing variant-typestate-views (b7e7a0a) to 4c67abc (merge-base) diff Run configurationrun benchmark variant_validation
shards: 1
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
run benchmark variant_kernels env: |
|
run benchmark variant_kernels env: resources: |
|
🤖 Benchmark starting (GKE) | trigger Target: variant_kernels Sharding factor: 1 (1 workers). Comparing variant-typestate-views (b7e7a0a) to 4c67abc (merge-base) diff Run configurationrun 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 |
|
🤖 Benchmark starting (GKE) | trigger Target: variant_kernels Sharding factor: 1 (1 workers). Comparing variant-typestate-views (b7e7a0a) to 4c67abc (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: ^(variant_get|shred_variant)
resources:
arch: amd64
shards: 1
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Target: variant_validation Comparing variant-typestate-views (b7e7a0a) to 4c67abc (merge-base) diff Run configurationrun benchmark variant_validation
shards: 1
DetailsPer-runner informationvariant_validation — shard 1/1Node: gk3-benchmark-cluster-nap-ufagysz2-36d0891d-l4j2 Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_validationCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Target: variant_kernels Comparing variant-typestate-views (b7e7a0a) to 4c67abc (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: ^(variant_get|shred_variant)
shards: 1
DetailsPer-runner informationvariant_kernels — shard 1/1Node: gk3-benchmark-cluster-nap-ufagysz2-36d0891d-j7hk Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernelsCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Target: variant_kernels Comparing variant-typestate-views (b7e7a0a) to 4c67abc (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: ^(variant_get|shred_variant)
resources:
arch: amd64
shards: 1
DetailsPer-runner informationvariant_kernels — shard 1/1Node: gk3-benchmark-cluster-nap-137sax4c-d5ffafd9-t2fz Instance: c4-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernelsCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
b7e7a0a to
7cd3412
Compare
7cd3412 to
c5c2121
Compare
|
run benchmark variant_kernels env: |
|
Hi @cetra3, your benchmark configuration could not be parsed (#11511 (comment)). Error: Usage: Any benchmark name is accepted: Per-side configuration ( env:
# shared env is inherited by BOTH the build and the run, so build
# flags go here. Builds default to no debuginfo for speed; opt back
# in for hung-job gdb dumps and cap jobs to stay within memory:
CARGO_PROFILE_RELEASE_DEBUG: "1"
CARGO_BUILD_JOBS: "1"
baseline:
ref: v45.0.0
env:
# per-side env only reaches the benchmark run, not the build
DATAFUSION_RUNTIME_MEMORY_LIMIT: 1G
changed:
ref: v46.0.0
env:
DATAFUSION_RUNTIME_MEMORY_LIMIT: 2GPod size and CPU architecture (each key is optional and keeps the default when absent; requests and limits are set equal): resources:
cpu: "16"
memory: "128Gi"
arch: arm64 # arm64 or amd64Independent benchmark shards (optional; 1–8, default 1): run benchmark arrow_writer
shards: 4Each shard builds both revisions, measures its assigned cases, and posts its own report. Resources and the job deadline apply per shard. DataFusion requests specifying a shard count greater than 1 fail with an error. Omit shards or use shards: 1 for DataFusion. File an issue against this benchmark runner |
|
run benchmark variant_kernels env: |
|
🤖 Benchmark starting (GKE) | trigger Target: variant_kernels Sharding factor: 1 (1 workers). Comparing variant-typestate-views (c5c2121) to 33d338d (merge-base) diff Run configurationrun 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 |
|
🤖 Benchmark completed (GKE) | trigger Target: variant_kernels Comparing variant-typestate-views (c5c2121) to 33d338d (merge-base) diff Run configurationrun benchmark variant_kernels
env:
BENCH_FILTER: ^(variant_get|shred_variant)
shards: 1
DetailsPer-runner informationvariant_kernels — shard 1/1Node: gk3-benchmark-cluster-nap-1o54riqp-92009ed2-g7jn Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_kernelsCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
c5c2121 to
dc3f9de
Compare
c63c93c to
235c590
Compare
235c590 to
475a482
Compare
Add MetadataView, ValueView, ObjectView and ListView: header-only views over encoded variant bytes with bounds-checked, fallible accessors and byte-wise name comparison. VariantMetadata, VariantObject and VariantList are now built by promoting a view, and delegate their accessors to it. variant_get reads unshredded columns through the views, shred_variant and unshred_variant copy residual fields by field id, and the borrowed_field_id lookup is removed. OffsetSizeBytes::unpack_u32_at_offset takes the size by value, so a temporary view does not have to stay on the stack for an out-of-line read. Upstream: apache#11511 (open), taken from its head 475a482.
6f01079 to
bccfc40
Compare
|
@sdf-jkl would you have capacity to help review this? |
|
Thanks @Jefffrey. It's been on my backlog for a few weeks. I'll prioritize it |
|
I ran the json bench tests using datafusion-variant in the following PR TLDR is this PR improves end to end performance significantly (25-40%) |
sdf-jkl
left a comment
There was a problem hiding this comment.
@cetra3 I see the performance improvement of the PR but I keep having trouble wrapping my head around the shape.
I was wondering if you could split this PR into separate smaller ones to make it easier to review/think about it.
I like the idea of the view layer for Variant to make the reading lazy, but I wonder if it requires adding a new mod with the APIs.
Some 🤖 findings in the comments below.
| pub fn insert_encoded(&mut self, field_id: u32, value: &[u8]) -> Result<(), ArrowError> { | ||
| let state = &mut self.parent_state; | ||
| let field_start = state.value_builder.offset() - state.saved_value_builder_offset; | ||
| if self.fields.insert(field_id, field_start).is_some() && self.validate_unique_fields { |
There was a problem hiding this comment.
🤖 💬 : Could we check for a duplicate before changing self.fields? insert replaces the original field's offset even when this method returns Err. If the caller continues using the builder, a later field can silently become the value of the rejected duplicate.
Minimal reproducer (save as parquet-variant/tests/pr11511_duplicate.rs):
use parquet_variant::{Variant, VariantBuilder};
#[test]
fn encoded_duplicate_preserves_original_value() {
let mut builder = VariantBuilder::new()
.with_field_names(["a", "b"])
.with_validate_unique_fields(true);
let mut object = builder.new_object();
object.insert_encoded(0, &[12, 1]).unwrap();
assert!(object.insert_encoded(0, &[12, 2]).is_err());
object.insert_encoded(1, &[12, 3]).unwrap();
object.finish();
let (metadata, value) = builder.finish();
let variant = Variant::try_new(&metadata, &value).unwrap();
assert_eq!(variant.get_object_field("a"), Some(Variant::Int8(1)));
assert_eq!(variant.get_object_field("b"), Some(Variant::Int8(3)));
}Run:
cargo test -p parquet-variant --test pr11511_duplicateExpected: the original a=1 survives the rejected insertion, and b=3 is appended. Actual: the first assertion fails with left: Some(Int8(3)), right: Some(Int8(1)); the finished object contains a=3, b=3 and passes Variant::try_new validation.
Reproduced on this PR and with its patch applied to upstream 7a1e79d0c2. The equivalent sequence using try_insert_bytes passes. An entry check that rejects the duplicate before mutation would preserve the existing insertion behavior.
There was a problem hiding this comment.
Good catch, this is a real bug: the rejected insert replaces the original offset.
I tried a fix locally: put the original offset back on the error path, plus your test. Together with the checked_add fix from your other comment, it measured about 2% slower on shred_variant_partial_object_8k_rows and shred_variant_unmatched_object_8k_rows on my machine, after subtracting about 1% of drift in an A/A control. The success path does no extra work, so I do not yet understand where that comes from. I want to investigate before I push a fix.
| Binary | String => 4 + u32::from_le_bytes(array_from_slice(value, 1)?) as usize, | ||
| }; | ||
| Ok(1 + payload) |
There was a problem hiding this comment.
🤖 💬 : Could both the length-prefix addition here and the header-byte addition below use checked arithmetic? On 32-bit targets, a length of u32::MAX overflows 4 + length; u32::MAX - 4 makes that addition succeed but overflows the subsequent 1 + payload. With overflow checks this panics; without them the total wraps to a small length, so a truncated encoding can be accepted by bytes().
Minimal regression test (save as parquet-variant/tests/pr11511_length.rs):
#[test]
fn truncated_large_payload_is_rejected() {
use parquet_variant::view::{MetadataView, ValueView};
use parquet_variant::EMPTY_VARIANT_METADATA_BYTES;
let metadata = MetadataView::try_new(EMPTY_VARIANT_METADATA_BYTES).unwrap();
for header in [0x3c, 0x40] { // Binary and long String
for length in [u32::MAX, u32::MAX - 4] {
let mut bytes = vec![header];
bytes.extend_from_slice(&length.to_le_bytes());
let value = ValueView::try_new(metadata, &bytes).unwrap();
assert!(value.bytes().is_err());
}
}
}On a machine with an installed 32-bit Rust target and its linker/runtime:
cargo test -p parquet-variant --test pr11511_length --target i686-unknown-linux-gnu
cargo test -p parquet-variant --test pr11511_length --target i686-unknown-linux-gnu --releaseExpected: all four malformed encodings return Err. On 32-bit with default debug overflow checks, the first case should panic in the addition; with default release wrapping, it should return Ok with a four-byte slice, failing the assertion.
This is an inspection finding: I compiled and ran this exact test on x86_64, where it passes, but have not run it on a 32-bit target. The arithmetic is unchanged when applying this PR to upstream 7a1e79d0c2. Using checked_add for both additions would return an error before slicing.
There was a problem hiding this comment.
Agreed, both additions can overflow on a 32-bit target.
I tried checked_add on both locally. I have not run it on a 32-bit target either. Together with the insert_encoded fix it looks about 2% slower on the two shred_variant_* benchmarks on my machine. On its own the difference was under 1%, which is inside the noise of my runs, so I cannot yet say how much of the slowdown is this change. It needs more investigation along with the other one.
|
@sdf-jkl how do you propose splitting this PR? |
alamb
left a comment
There was a problem hiding this comment.
Thank you @cetra3 and @sdf-jkl
I agree this looks like a good change and it would be sweet to land. Thank you for your patience
I think the biggest mental lift is understanding the view design.
In terms of how to spit it up, perhaps we can break it up into some independent piece. Here are some potential places to chunk:
- Refactor only (like OffsetSizeBytes by value, drop unpack_u32, extract str_from_bytes, etc)
- The stuff in
builder-- likeMetadataBuilder::cmp_field_names - Revive the code from to compare bytes #11505 (maybe just reopen that PR)
- Then maybe add the View API and Revive #11506 (extract straight from bytes)
| mod list; | ||
| mod metadata; | ||
| mod object; | ||
| #[doc(hidden)] |
There was a problem hiding this comment.
what is the rationale for this?
There was a problem hiding this comment.
Honestly it was to prevent larger api surface area, but I am using these view structs in some of our downstream code, to get speed benefits, so I think if maintainers are happy to have them added, then we can omit this.
bccfc40 to
a1637dd
Compare
|
@alamb @sdf-jkl I have split this into a stack of smaller PRs, as you asked:
Each one is stacked on the one before, so 2–4 are drafts until their parent merges. This PR stays open as the end state. Once the four land, it rebases down to the removal of One thing to know before you review: the first two PRs are slower on some benchmarks, and the gains only arrive once the whole shape lands. I benchmarked each PR against its parent, locally on x86_64:
Each PR's description has its own table. If you would rather not merge PRs that are slower on their own, I can fold 1 into 2, or 2 into 3. |
…ache#12308) # Which issue does this PR close? - Part of apache#11511 This is the first of a stack of PRs that split apache#11511 into smaller pieces, as its reviewers asked. # Rationale for this change apache#11511 adds header-only views of encoded variant bytes. The views read offsets and field names straight from the encoded buffer, and these helpers are in the way of that. This PR makes the helper changes on their own, so that the later PRs only show the views. # What changes are included in this PR? - `OffsetSizeBytes::unpack_u32_at_offset` takes `self` by value. `OffsetSizeBytes` is `Copy`. - `OffsetSizeBytes::unpack_u32` is removed. It was `unpack_u32_at_offset` with a byte offset of 0, and its callers now call that. - `str_from_bytes` is extracted from `string_from_slice`, which now calls it. All of these items are crate-private. # Are these changes tested? The existing tests cover the changed code. The `unpack_u32` tests now call `unpack_u32_at_offset`. # Are there any user-facing changes? No. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Add MetadataView, ValueView, ObjectView and ListView: header-only views over encoded variant bytes with bounds-checked, fallible accessors and byte-wise name comparison. VariantMetadata, VariantObject and VariantList are now built by promoting a view, and delegate their accessors to it. variant_get reads unshredded columns through the views, shred_variant and unshred_variant copy residual fields by field id, and the borrowed_field_id lookup is removed. OffsetSizeBytes::unpack_u32_at_offset takes the size by value, so a temporary view does not have to stay on the stack for an out-of-line read.
Rename the views to `VariantView`, `VariantMetadataView`, `VariantObjectView` and `VariantListView`, and export them from the crate root in place of the hidden `view` module. Export `VariantBasicType`, which `VariantView::basic_type` returns. Move the design notes to the `VariantView` docs with an example, and test the views directly, including on truncated and corrupt input. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
a1637dd to
557aa93
Compare
|
Converting to draft so we can focus on the stacked PRs |
Which issue does this PR close?
This PR supersedes #11505 and #11506. It makes the same changes in a general form.
Rationale for this change
Every access to a variant value pays for checks that the access does not use.
Variant::newand the unvalidated constructors ofVariantMetadata,VariantObjectandVariantListread the first and last offsets of each header and trim the byte slices. A field lookup then validates the UTF-8 of every dictionary name that its binary search probes. Kernels such asvariant_getconstruct a fullVariantfor every row, and then walk the path through it.For most kernel work, a value needs much less: the header of each object or list along a path, the names that the binary search probes, and the bytes of the value that it finds.
What changes are included in this PR?
VariantView,VariantMetadataView,VariantObjectViewandVariantListViewview encoded variant bytes.strdoes, so a search does not validate UTF-8.VariantMetadataView::into_metadata,VariantObjectView::into_object,VariantListView::into_listandVariantView::to_variantadd the first and last offset checks that unvalidated instances guarantee.VariantMetadata,VariantObjectandVariantListare now built by promoting a view, and their accessors (get,field,field_name,iter,get_entry) delegate to it. Their public behavior is unchanged.variant_getreads unshredded columns through the views, for field and index paths and for typed andVariantoutput. A row reads only the headers and names along the path, and decodes only the value that it finds.shred_variantandunshred_variantcopy leftover object fields by field id with their encoded bytes, through a newObjectBuilder::insert_encoded. A leftover field is no longer decoded into aVariantand then re-encoded.ObjectBuilder::finishsorts fields with a newMetadataBuilder::cmp_field_names.ReadOnlyMetadataBuildercompares the names as bytes.VariantMetadata::borrowed_field_idis removed. No caller in the repository needs it after the changes above. Its tests now coverget_entry.Are these changes tested?
The existing tests of
parquet-variant,parquet-variant-compute,parquet-variant-json, and theparquetvariant integration tests pass. The existing types now delegate to the views, so their tests also cover the views. The views also have direct tests: agreement withVariantMetadata,VariantObject,VariantListandVariant::get_path,VariantView::bytesfor every primitive type, and every truncation and single-byte corruption of a sample value, which must not panic.Benchmarks (local run,
mainvs this PR, back to back, Apple Silicon laptop):variant_get_unshredded_object_path_262k_rowsvariant_get_list_index_unshreddedvariant_get_utf8_from_intvariant_get_utf8_from_unshredded_stringvariant_get_binary_from_unshredded_binaryvariant_get_utf8_from_listvariant_get_utf8_from_map_in_listshred_variant_partial_object_8k_rowsshred_variant_unmatched_object_8k_rowsvariant_get_list_index_shreddedvariant_get_shredded_utf8object_get_by_name/128object_iter/128object_field_name/128metadata_iter/128bench_validate_large_objectbench_validate_large_nested_listThe 16
variant_get_decimal_*benchmarks are 25–36% faster. No benchmark invariant_kernelsorvariant_validationis more than 2% slower.On real-world telemetry data with per-row metadata,
variant_geton unshredded object fields is 1.6–1.9x faster thanmainfor keys that most rows contain, and 2.2–2.4x faster for keys that are rare or absent.Are there any significant user-facing changes?
New public API in
parquet-variant:VariantView,VariantMetadataView,VariantObjectViewandVariantListView, with their methods.VariantMetadata::view,VariantObject::viewandVariantList::view.ObjectBuilder::insert_encoded.MetadataBuilder::cmp_field_names, a provided trait method.VariantBasicType, whichVariantView::basic_typereturns.No existing public API changes. Behavior differences:
variant_get,shred_variantand the residual copy inunshred_variantreturn an error, or a null under safe casting. Before, these paths could panic.ObjectBuilder::insert_bytesnow resolves them throughget_entryand the existing name cache, not throughborrowed_field_id.