JingsongLi commented on code in PR #1405:
URL: https://github.com/apache/paimon-rust/pull/1405#discussion_r4663586728
##########
crates/paimon/src/variant.rs:
##########
@@ -1436,15 +1453,58 @@ impl RebuildMetadata {
}
}
-/// Bound parsed dictionaries to one assembly call. Exact bytes, not a hash or
-/// an address, determine whether field IDs can be reused.
+/// Bound parsed dictionaries and compact validation results to one assembly
call.
+/// Arrow batches can also borrow validated metadata without copying its bytes.
#[derive(Default)]
-pub(crate) struct RebuildMetadataCache {
+pub(crate) struct RebuildMetadataCache<'a> {
entries: VecDeque<Arc<RebuildMetadata>>,
bytes: usize,
-}
+ validated: VecDeque<Box<[u8]>>,
+ validated_bytes: usize,
+ validated_borrowed: HashSet<&'a [u8]>,
+ validated_borrowed_addresses: HashSet<(usize, usize)>,
+}
+
+impl<'a> RebuildMetadataCache<'a> {
+ fn validate_compact_metadata_borrowed(&mut self, bytes: &'a [u8]) ->
Result<()> {
+ // The source Arrow array is immutable throughout this cache's
lifetime.
+ // Check its slice address first so repeated dictionary values are
O(1).
+ let address = (bytes.as_ptr() as usize, bytes.len());
+ if self.validated_borrowed_addresses.contains(&address) {
+ return Ok(());
+ }
+ if !self.validated_borrowed.contains(bytes) {
Review Comment:
**[P2] Avoid hashing the full source dictionary on every row**
The batch cache now reuses validation beyond the 2 MiB limit. Full Variant
reads still decode metadata into a `BinaryArray`. Each nonempty row has a
distinct slice address, so repeated dictionaries reach this content lookup and
hash the whole slice. In a CPU sample of the reproducer, about 70% of the Arrow
rebuild samples were in slice hashing.
I reran the 512-row Parquet fixture with a fully typed `age BIGINT`, no
residual, and 18 rotating dictionaries of 123,339 bytes each. The median Arrow
rebuild time after decoding was **143.6 ms** over 14 debug samples on
`2279f8d0`. Earlier measurements with the same setup were **2.7 ms** on the
merge base `cb8633dc` and **789.4 ms** on `a283a180`.
Could full Variant reads reuse the existing Arrow dictionary metadata path
and cache successful validation by dictionary key?
--
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]