martin-g commented on code in PR #22829:
URL: https://github.com/apache/datafusion/pull/22829#discussion_r3376101694


##########
datafusion/execution/src/cache/file_metadata_cache.rs:
##########
@@ -73,23 +89,27 @@ impl DefaultFilesMetadataCacheState {
         }
 
         self.cache_hits.insert(key.clone(), 0);
+        let sized = SizedCacheEntry {
+            entry: value,
+            size: value_size,
+        };
         // if the key is already in the cache, the old value is removed
-        let old_value = self.lru_queue.put(key, value);
+        let old_value = self.lru_queue.put(key, sized);
         self.memory_used += value_size;
-        if let Some(ref old_entry) = old_value {
-            self.memory_used -= old_entry.file_metadata.memory_size();
+        if let Some(ref old) = old_value {
+            self.memory_used -= old.size;
         }
 
         self.evict_entries();
 
-        old_value
+        old_value.map(|s| s.entry)
     }
 
     /// Evicts entries from the LRU cache until `memory_used` is lower than 
`memory_limit`.
     fn evict_entries(&mut self) {
         while self.memory_used > self.memory_limit {
             if let Some(removed) = self.lru_queue.pop() {
-                self.memory_used -= removed.1.file_metadata.memory_size();
+                self.memory_used -= removed.1.size;

Review Comment:
   ```suggestion
                   self.memory_used -= removed.1.size;
                   self.cache_hits.remove(&removed.0);
   ```
   



##########
datafusion/execution/src/cache/file_metadata_cache.rs:
##########
@@ -46,9 +57,12 @@ impl DefaultFilesMetadataCacheState {
     /// Returns the respective entry from the cache, if it exists.
     /// If the entry exists, it becomes the most recently used.
     fn get(&mut self, k: &Path) -> Option<CachedFileMetadataEntry> {
-        self.lru_queue.get(k).cloned().inspect(|_| {
-            *self.cache_hits.entry(k.clone()).or_insert(0) += 1;
-        })
+        self.lru_queue
+            .get(k)
+            .map(|sized| sized.entry.clone())
+            .inspect(|_| {
+                *self.cache_hits.entry(k.clone()).or_insert(0) += 1;

Review Comment:
   ```suggestion
                   if let Some(hits) = self.cache_hits.get_mut(k) {
                       *hits += 1;
                   }
   ```
   If the key exists in `lru_queue` then it should exist in the `cache_hits` 
too and you can avoid the path cloning.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to