[ty] Track heap usage of salsa structs (#19790)

Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
Ibraheem Ahmed 2025-08-12 07:28:44 -04:00 committed by GitHub
parent 6a05d46ef6
commit f34b65b7a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 269 additions and 124 deletions

View file

@ -1,6 +1,7 @@
use std::sync::{LazyLock, Mutex};
use get_size2::{GetSize, StandardTracker};
use ordermap::OrderSet;
/// Returns the memory usage of the provided object, using a global tracker to avoid
/// double-counting shared objects.
@ -12,3 +13,8 @@ pub fn heap_size<T: GetSize>(value: &T) -> usize {
.get_heap_size_with_tracker(&mut *TRACKER.lock().unwrap())
.0
}
/// An implementation of [`GetSize::get_heap_size`] for [`OrderSet`].
pub fn order_set_heap_size<T: GetSize, S>(set: &OrderSet<T, S>) -> usize {
(set.capacity() * T::get_stack_size()) + set.iter().map(heap_size).sum::<usize>()
}