alamb commented on code in PR #10879:
URL: https://github.com/apache/arrow-rs/pull/10879#discussion_r3874143263
##########
parquet-variant/src/variant/metadata.rs:
##########
@@ -368,7 +368,27 @@ impl<'m> VariantMetadata<'m> {
/// [invalid]: Self#Validation
pub fn get(&self, i: usize) -> Result<&'m str, ArrowError> {
let byte_range = self.get_offset(i)? as _..self.get_offset(i + 1)? as
_;
- string_from_slice(self.bytes, self.first_value_byte as _, byte_range)
+ if !self.validated {
+ return string_from_slice(self.bytes, self.first_value_byte as _,
byte_range);
+ }
+
+ // Full validation already proved every dictionary entry is valid
UTF-8, so validating
+ // again here would charge that cost once per field access instead of
once per buffer.
+ let value_bytes =
+ slice_from_slice_at_offset(self.bytes, self.first_value_byte as _,
byte_range)?;
+
+ // Belt and braces: in debug builds (which is how the proptest suite in
Review Comment:
"belt and braces"? I think we could probably avoid this comment, leaving the
debug assert is probably good but the comment just makes the code harder to
read i my opionion
##########
parquet-variant/src/variant/metadata.rs:
##########
@@ -368,7 +368,27 @@ impl<'m> VariantMetadata<'m> {
/// [invalid]: Self#Validation
pub fn get(&self, i: usize) -> Result<&'m str, ArrowError> {
let byte_range = self.get_offset(i)? as _..self.get_offset(i + 1)? as
_;
- string_from_slice(self.bytes, self.first_value_byte as _, byte_range)
+ if !self.validated {
+ return string_from_slice(self.bytes, self.first_value_byte as _,
byte_range);
+ }
+
+ // Full validation already proved every dictionary entry is valid
UTF-8, so validating
+ // again here would charge that cost once per field access instead of
once per buffer.
+ let value_bytes =
+ slice_from_slice_at_offset(self.bytes, self.first_value_byte as _,
byte_range)?;
+
+ // Belt and braces: in debug builds (which is how the proptest suite in
+ // `tests/proptest.rs` runs) re-check the invariant the unchecked
conversion relies on,
+ // so a future change that breaks it fails a test instead of causing
undefined behavior.
+ debug_assert!(std::str::from_utf8(value_bytes).is_ok());
+
+ // SAFETY: `validated` is set only by `with_full_validation`, which
proves that
Review Comment:
I think this comment could be less too
```rust
// SAFETY: `validated` is set only by `with_full_validation`, which proves
that
// `self.bytes[self.first_value_byte..]` is valid UTF-8.
```
##########
parquet-variant/benches/variant_metadata_access.rs:
##########
@@ -0,0 +1,147 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Benchmarks for reading field names out of an already-validated variant
+//! metadata dictionary.
+//!
+//! The shape modelled here is a write-heavy workload that stores
semi-structured
+//! attributes as Variant: a modest dictionary of short, ASCII field names
that is
+//! validated once and then read many times, once per object field access.
+
+use criterion::*;
+use parquet_variant::{Variant, VariantBuilder, VariantMetadata};
+use std::hint::black_box;
+
+/// Short, ASCII field names, in the style of telemetry / log attribute keys.
Review Comment:
Is there an existing variant benchmark we could add this to?
--
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]