nikolaobradovic-db commented on code in PR #12483:
URL: https://github.com/apache/arrow-rs/pull/12483#discussion_r4722145694


##########
parquet/src/util/interner.rs:
##########
@@ -40,11 +40,23 @@ impl<S: Storage> Interner<S> {
     pub fn new(storage: S) -> Self {
         Self {
             state: Default::default(),
-            dedup: HashTable::with_capacity(DEFAULT_DEDUP_CAPACITY),
+            // Start empty: a column that gets no value never needs the table. 
The
+            // dictionary encoder reserves the full table before its first 
value
+            // (`reserve_if_empty`), as growing from empty is slower.
+            dedup: HashTable::new(),
             storage,
         }
     }
 
+    /// Reserves `DEFAULT_DEDUP_CAPACITY` entries if the table has none yet.
+    pub(crate) fn reserve_if_empty(&mut self) {

Review Comment:
   I moved the laziness into `DictEncoder` in f9f86090c: `interner` is now 
`Option<Interner<_>>`, created by the first non-empty `put`, and `Interner` is 
unchanged from `main`. Memory on `wide_sparse_int64` is the same as before, and 
the timing benches show no difference from the previous version.
   
   I didn't go with `dedup: Option<HashTable>`. An empty `HashTable` already 
doesn't allocate, and enforcing it inside `intern` adds a check per value. A 
capacity check in `intern` measured 1-3% slower on `primitive/default` and the 
`ndv/fsb16` case.
   



-- 
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]

Reply via email to