JingsongLi commented on code in PR #1405:
URL: https://github.com/apache/paimon-rust/pull/1405#discussion_r4674907100
##########
crates/paimon/src/variant.rs:
##########
@@ -1436,15 +1453,70 @@ 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)>,
+ validated_dictionary_keys: HashSet<i32>,
}
-impl RebuildMetadataCache {
+impl<'a> RebuildMetadataCache<'a> {
+ fn validate_compact_metadata_borrowed(
+ &mut self,
+ bytes: &'a [u8],
+ dictionary_key: Option<i32>,
+ ) -> Result<()> {
+ if let Some(key) = dictionary_key {
+ if !self.validated_dictionary_keys.contains(&key) {
+ validate_metadata(bytes)?;
+ self.validated_dictionary_keys.insert(key);
+ }
+ return Ok(());
+ }
+ // 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 same wide dictionary for every row**
When a compact rebuild needs a residual field, it reaches this lookup. Each
row has a separate `BinaryArray` slice, so the address cache misses and
`contains(bytes)` hashes the entire dictionary even when all rows share the
same metadata. These dictionaries fit in `main`'s validation cache, where hits
only need a byte comparison.
I reproduced this on the same persisted 512-row Paimon Parquet file with
`{"age":27,"cold":1}`, `age` shredded as `BIGINT`, and a shared 123,357-byte
source dictionary. The metadata column had one `RLE_DICTIONARY` data page. With
identical compiler settings, the median from scan planning through Arrow
materialization rose from **9.0–13.3 ms** on `e7e9a4dc` to **19.0–19.7 ms** on
`58cf78b5` across two rounds of 11 warm scans per build. Both builds returned
the same values.
Could we compare the full bytes against a small cache of recently validated
dictionaries before falling back to content hashing?
--
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]