Repository navigation
refactor(variant): simplify the offset and UTF-8 decoding helpers - #12308
Merged
Merged
Conversation
This was referenced Nov 18, 2026
Member
|
run benchmark variant_kernels |
|
🤖 Benchmark starting (GKE) | trigger Target: variant_kernels Sharding factor: 1 (1 workers). Comparing variant-views-1-refactor (4b8187e) to e28432b (merge-base) diff Run configurationrun benchmark variant_kernels
shards: 1
Results will be posted when all workers finish. File an issue against this benchmark runner |
sdf-jkl
approved these changes
Nov 19, 2026
sdf-jkl
left a comment
Member
There was a problem hiding this comment.
LGTM, the perf regression you mentioned doesn't reproduce on my x86 machine
Take `OffsetSizeBytes` by value in `unpack_u32_at_offset`, remove `unpack_u32` in favor of it, and extract `str_from_bytes` from `string_from_slice`. Co-Authored-By: Claude Fable 5.2 <[email protected]>
cetra3
force-pushed
the
variant-views-1-refactor
branch
from
November 19, 2026 04:21
4b8187e to
cd32a6f
Compare
|
🤖 Benchmark completed (GKE) | trigger Target: variant_kernels Comparing variant-views-1-refactor (4b8187e) to e28432b (merge-base) diff Run configurationrun benchmark variant_kernels
shards: 1
DetailsPer-runner informationvariant_kernels — shard 1/1Node: gk3-benchmark-cluster-nap-hlsk0klo-fe6a26fa-rsn5 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 |
adriangb
added a commit
to pydantic/arrow-rs
that referenced
this pull request
Nov 26, 2026
Subodh-17
pushed a commit
to Subodh-17/arrow-rs
that referenced
this pull request
Nov 29, 2026
…#12309) # Which issue does this PR close? - Part of apache#11511 This PR is the first open PR of the stack split out of apache#11511. apache#12308 has merged, so the diff is this PR's change alone. # Rationale for this change Every access to a variant value pays for checks that the access does not use. The unvalidated constructors of `VariantMetadata`, `VariantObject` and `VariantList` read 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. 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. This PR adds the types that read that way, and builds the existing types on them. The kernels start to use the views in the next PRs of the stack. # What changes are included in this PR? - New types `VariantView`, `VariantMetadataView`, `VariantObjectView` and `VariantListView`. - Building a view reads one header and nothing else. - Each accessor reads and bounds-checks only the bytes that it needs, and returns an error on malformed input. It never panics. - Field names are compared as bytes, which orders them as `str` does, so a search does not validate UTF-8. - A view converts to the existing types: `VariantMetadataView::try_into_metadata`, `VariantObjectView::try_into_object`, `VariantListView::try_into_list` and `VariantView::try_to_variant` add the first and last offset checks that unvalidated instances guarantee. - `VariantMetadata`, `VariantObject` and `VariantList` are now built by promoting a view, and their accessors (`get`, `field`, `field_name`, `iter`, `get_entry`) delegate to it. Their public behavior is unchanged. - `ObjectBuilder::finish` sorts fields with a new `MetadataBuilder::cmp_field_names`. `ReadOnlyMetadataBuilder` compares the names as bytes. The docs of `VariantView` describe the design. # Are these changes tested? The existing types now delegate to the views, so their tests also cover the views. The views also have direct tests: agreement with `VariantMetadata`, `VariantObject` and `VariantList`, and every truncation and single-byte corruption of a sample value, which must not panic. Benchmark runner results, this PR against `main`: `variant_validation` on [x86_64](apache#12309 (comment)) and [Neoverse V2](apache#12309 (comment)), and `variant_kernels` on [x86_64](apache#12309 (comment)). | benchmark | x86_64 | Neoverse V2 | |---|---:|---:| | `metadata_iter/8` | −1% | −5% | | `metadata_iter/32` | +5% | −7% | | `metadata_iter/128` | +4% | −6% | | `bench_validate_complex_object` | −1% | 0% | | `bench_validate_large_object` | 0% | −7% | | `bench_validate_large_nested_list` | −1% | 0% | | `object_field_name/{8,32,128}` | −2% | −2% to −3% | | `object_get_by_name/8` | −15% | +1% | | `object_get_by_name/32` | −17% | −4% | | `object_get_by_name/128` | −21% | −9% | | `object_iter/8` | −7% | −10% | | `object_iter/32` | −9% | −8% | | `object_iter/128` | −11% | −8% | | `variant_get_unshredded_object_path_262k_rows` | +3% | | | `variant_get_list_index_unshredded` | +2% | | | `variant_get_utf8_from_list` | +3% | | | `variant_get_utf8_from_map_in_list` | +3% | | | `variant_get_utf8_from_unshredded_string` | −6% | | | `variant_get_decimal_short_string_to_decimal256(76,2)_wide_8192_safe` | +11% | | | `variant_get_decimal_string_to_decimal128(38,3)_long_8192_safe` | +9% | | | `variant_get_decimal_string_to_decimal128(38,3)_long_8192_strict` | +6% | | | `unshred_variant_object` | −5% | | | `unshred_variant_list` | −6% | | | `unshred_variant_partial_object` | +3% | | | `unshred_variant_partial_object_unsorted_metadata` | −19% | | Slower inputs: - `metadata_iter` is 4–5% slower on x86_64 at 32 and 128 entries, and 5–7% faster on Neoverse V2. My local x86_64 machine measured it 13–16% slower. - Three `variant_get` benchmarks that cast long strings to decimals are 6–11% slower on x86_64. I have not found the cause. This PR does not change the string decoding or decimal parsing code. On that path it only changes how `VariantMetadata` is built, which does the same checks as before. - The four unshredded `variant_get` benchmarks that read objects or lists are 2–3% slower on x86_64. The next PR of the stack moves `variant_get` onto the views. # Are there any user-facing changes? New public API in `parquet-variant`: - `VariantView`, `VariantMetadataView`, `VariantObjectView` and `VariantListView`, with their methods. - `VariantMetadata::view`, `VariantObject::view` and `VariantList::view`. - `MetadataBuilder::cmp_field_names`, a provided trait method. - `VariantBasicType`, which `VariantView::basic_type` returns. No existing public API changes. Some out-of-range errors from metadata and list accessors have new message text. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5.2 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
This is the first of a stack of PRs that split #11511 into smaller pieces, as its reviewers asked.
Rationale for this change
#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_offsettakesselfby value.OffsetSizeBytesisCopy.OffsetSizeBytes::unpack_u32is removed. It wasunpack_u32_at_offsetwith a byte offset of 0, and its callers now call that.str_from_bytesis extracted fromstring_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_u32tests now callunpack_u32_at_offset.Are there any user-facing changes?
No.
🤖 Generated with Claude Code