pub struct MemoryTracker { /* private fields */ }Expand description
Tracks memory usage for a single keyspace.
All updates are explicit — callers must call add / remove on every
mutation. This avoids any hidden scanning cost.
Implementations§
Source§impl MemoryTracker
impl MemoryTracker
Sourcepub fn used_bytes(&self) -> usize
pub fn used_bytes(&self) -> usize
Returns the current estimated memory usage in bytes.
Sourcepub fn replace(&mut self, key: &str, old_value: &Value, new_value: &Value)
pub fn replace(&mut self, key: &str, old_value: &Value, new_value: &Value)
Adjusts tracking when a key’s value is overwritten.
Removes the old value’s contribution and adds the new one. Key count stays the same.
Sourcepub fn adjust(&mut self, old_entry_size: usize, new_entry_size: usize)
pub fn adjust(&mut self, old_entry_size: usize, new_entry_size: usize)
Adjusts used bytes for an in-place mutation (e.g. list push/pop) without changing the key count.
old_entry_size and new_entry_size are the full entry sizes
(as returned by entry_size) before and after the mutation.
Sourcepub fn grow_by(&mut self, delta: usize)
pub fn grow_by(&mut self, delta: usize)
Increases used bytes by delta without scanning the entry.
Use this when the caller already knows the exact number of bytes being added (e.g. list push where element sizes are precomputed). Does not change the key count.
Sourcepub fn shrink_by(&mut self, delta: usize)
pub fn shrink_by(&mut self, delta: usize)
Decreases used bytes by delta without scanning the entry.
Use this when the caller already knows the exact number of bytes being removed (e.g. list pop where the popped element length is known). Does not change the key count.
Sourcepub fn remove_with_size(&mut self, size: usize)
pub fn remove_with_size(&mut self, size: usize)
Removes an entry with an explicit size, useful when the value has already been mutated and the original size was captured beforehand.