sdf-jkl opened a new pull request, #12430: URL: https://github.com/apache/arrow-rs/pull/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) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
