This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new bdf17ede6f perf(variant): skip re-validating children of fully
validated objects and lists (#12430)
bdf17ede6f is described below
commit bdf17ede6f47bd4099d39ccab17abb1d72cad391
Author: Kosta Tarasov <[email protected]>
AuthorDate: Tue Nov 24 14:47:13 2026 +0000
perf(variant): skip re-validating children of fully validated objects and
lists (#12430)
# Which issue does this PR close?
- Follow-up to #11106, which made `unshred_variant_nested_fallback`
1.85x slower on the benchmark runner.
# Rationale for this change
`VariantObject::iter_try` and `VariantList::iter_try` call
`with_full_validation()` on every child, and
`ValueBuilder::try_append_variant` then recurses into each child object
or list and calls `iter_try` again. A value nested `d` levels deep is
fully validated about `d` times. With #11106, `unshred_variant` takes
this path for fallback values, even though it has already fully
validated each value with `Variant::try_new_with_metadata`.
Full validation of an object or list recursively validates all of its
children, so every child of a validated value is already valid. The
accessors build each child with only shallow checks, so the child loses
that fact and gets validated again. This is the same problem #10879
fixed for metadata dictionary entries.
# What changes are included in this PR?
`VariantObject` and `VariantList` mark a child as fully validated when
they build it from a fully validated parent. `with_full_validation` on
such a child returns immediately, so `iter_try`, `try_field` and
`try_get` no longer re-validate subtrees. Children of unvalidated
parents are built and validated as before.
This conflicts with #12309 from @cetra3, which rewrites the code that
builds child values. The resolution adds the same one-line call where
#12309 builds children, and I am happy to do it in whichever PR lands
second.
# Are these changes tested?
`test_children_inherit_full_validation` checks that the fields and list
elements of a validated value report `is_fully_validated()`, and that
those of an unvalidated value do not. It fails if either the object or
the list half of the change is removed.
`unshred_variant_nested_fallback` from `variant_kernels` (local x86,
`codegen-units=1`):
| | time |
|---|---|
| before #11106 | 89.7 ms |
| #11106 | 159.8 ms |
| #11106 and this PR | 87.1 ms |
Removing the `with_full_validation()` calls from both `iter_try`
implementations entirely gives about the same time (88.8 ms), so the
re-validation accounts for the whole regression.
# Are there any significant user-facing changes?
Children returned by the accessors of a fully validated `VariantObject`
or `VariantList` (`field`, `get`, `iter` and their fallible versions)
now report `is_fully_validated() == true`. They reported `false` before,
although they were valid. No public API changes.
# AI usage disclosure
Claude Code helped find the cause, write the change and test, and run
the benchmarks. I reviewed the change and the measurements.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
parquet-variant/src/variant.rs | 36 +++++++++++++++++++++++++++++++++++
parquet-variant/src/variant/list.rs | 3 ++-
parquet-variant/src/variant/object.rs | 3 ++-
3 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/parquet-variant/src/variant.rs b/parquet-variant/src/variant.rs
index 3bfa0f05c8..e8175bdec9 100644
--- a/parquet-variant/src/variant.rs
+++ b/parquet-variant/src/variant.rs
@@ -485,6 +485,17 @@ impl<'m, 'v> Variant<'m, 'v> {
}
}
+ // Validating an object or list also validates all of its children, so a
child of a fully
+ // validated parent is marked validated instead of being validated again.
+ fn inherit_validation(mut self, parent_validated: bool) -> Self {
+ match &mut self {
+ Variant::List(list) => list.validated = parent_validated,
+ Variant::Object(obj) => obj.validated = parent_validated,
+ _ => {}
+ }
+ self
+ }
+
/// Converts this variant to `()` if it is null.
///
/// Returns `Some(())` for null variants,
@@ -1844,6 +1855,31 @@ impl std::fmt::Debug for Variant<'_, '_> {
mod tests {
use super::*;
+ use crate::VariantBuilder;
+
+ #[test]
+ fn test_children_inherit_full_validation() {
+ let mut builder = VariantBuilder::new();
+ let mut object = builder.new_object();
+ object.new_object("o").finish();
+ let mut list = object.new_list("l");
+ list.new_list().finish();
+ list.finish();
+ object.finish();
+ let (metadata, value) = builder.finish();
+
+ for (variant, validated) in [
+ (Variant::new(&metadata, &value), false),
+ (Variant::try_new(&metadata, &value).unwrap(), true),
+ ] {
+ let object = variant.as_object().unwrap();
+ let fields: Vec<_> = object.iter().map(|(_, v)|
v.is_fully_validated()).collect();
+ assert_eq!(fields, [validated, validated]);
+ let list = object.get("l").unwrap();
+ let element = list.as_list().unwrap().get(0).unwrap();
+ assert_eq!(element.is_fully_validated(), validated);
+ }
+ }
#[test]
fn test_empty_variant_will_fail() {
diff --git a/parquet-variant/src/variant/list.rs
b/parquet-variant/src/variant/list.rs
index b51e79c5d9..c125cf39af 100644
--- a/parquet-variant/src/variant/list.rs
+++ b/parquet-variant/src/variant/list.rs
@@ -112,7 +112,7 @@ pub struct VariantList<'m, 'v> {
header: VariantListHeader,
num_elements: u32,
first_value_byte: u32,
- validated: bool,
+ pub(super) validated: bool,
}
// We don't want this to grow because it could increase the size of `Variant`
and hurt performance.
@@ -294,6 +294,7 @@ impl<'m, 'v> VariantList<'m, 'v> {
let value_bytes =
slice_from_slice_at_offset(self.value, self.first_value_byte as _,
byte_range)?;
Variant::try_new_with_metadata_and_shallow_validation(self.metadata.clone(),
value_bytes)
+ .map(|child| child.inherit_validation(self.validated))
}
/// Iterates over the values of this list. When working with [unvalidated]
input, consider
diff --git a/parquet-variant/src/variant/object.rs
b/parquet-variant/src/variant/object.rs
index acb568aa99..ba1e9eab8a 100644
--- a/parquet-variant/src/variant/object.rs
+++ b/parquet-variant/src/variant/object.rs
@@ -111,7 +111,7 @@ pub struct VariantObject<'m, 'v> {
num_elements: u32,
first_field_offset_byte: u32,
first_value_byte: u32,
- validated: bool,
+ pub(super) validated: bool,
}
// We don't want this to grow because it could increase the size of `Variant`
and hurt performance.
@@ -354,6 +354,7 @@ impl<'m, 'v> VariantObject<'m, 'v> {
let value_bytes = slice_from_slice(self.value, self.first_value_byte
as _..)?;
let value_bytes = slice_from_slice(value_bytes, self.get_offset(i)? as
_..)?;
Variant::try_new_with_metadata_and_shallow_validation(self.metadata.clone(),
value_bytes)
+ .map(|child| child.inherit_validation(self.validated))
}
// Attempts to retrieve the ith offset from the field offset region of the
byte buffer.