comphead commented on code in PR #3924:
URL: https://github.com/apache/datafusion-comet/pull/3924#discussion_r3070760414
##########
native/core/src/execution/jni_api.rs:
##########
@@ -141,15 +141,29 @@ fn unregister_and_total(thread_id: u64, context_id: i64)
-> usize {
map.remove(&thread_id);
return 0;
}
- return pools.values().map(|p| p.reserved()).sum::<usize>();
+ let mut seen = std::collections::HashSet::new();
+ return pools
+ .values()
+ .filter(|p| seen.insert(Arc::as_ptr(p) as *const () as usize))
+ .map(|p| p.reserved())
+ .sum::<usize>();
Review Comment:
```suggestion
return pools
.values()
.filter_map(|p| {
let ptr = Arc::as_ptr(p) as *const ();
seen.insert(ptr).then(|| p.reserved())
})
```
##########
native/core/src/execution/jni_api.rs:
##########
@@ -141,15 +141,29 @@ fn unregister_and_total(thread_id: u64, context_id: i64)
-> usize {
map.remove(&thread_id);
return 0;
}
- return pools.values().map(|p| p.reserved()).sum::<usize>();
+ let mut seen = std::collections::HashSet::new();
+ return pools
+ .values()
+ .filter(|p| seen.insert(Arc::as_ptr(p) as *const () as usize))
+ .map(|p| p.reserved())
+ .sum::<usize>();
}
0
}
fn total_reserved_for_thread(thread_id: u64) -> usize {
let map = get_thread_memory_pools().lock();
map.get(&thread_id)
- .map(|pools| pools.values().map(|p| p.reserved()).sum::<usize>())
+ .map(|pools| {
+ // Deduplicate pools that share the same underlying allocation
+ // (e.g. task-shared pools registered by multiple execution
contexts)
+ let mut seen = std::collections::HashSet::new();
+ pools
+ .values()
+ .filter(|p| seen.insert(Arc::as_ptr(p) as *const () as usize))
Review Comment:
same
--
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]