diff --git a/third-party/rust/starlark-rust/starlark/src/values/layout/arena.rs b/third-party/rust/starlark-rust/starlark/src/values/layout/arena.rs index 8b58a2e62a3..d319e5be22c 100644 --- a/third-party/rust/starlark-rust/starlark/src/values/layout/arena.rs +++ b/third-party/rust/starlark-rust/starlark/src/values/layout/arena.rs @@ -117,6 +117,10 @@ impl Arena { self.drop.allocated_bytes() + self.non_drop.allocated_bytes() } + pub fn available_bytes(&self) -> usize { + self.drop.chunk_capacity() + self.non_drop.chunk_capacity() + } + /// Bytes allocated which can't be iterated over pub fn allocated_bytes_inline(&self) -> usize { self.non_drop.allocated_bytes() @@ -478,6 +482,6 @@ mod test { assert_eq!(res.len(), 1); let entry = res.values().next().unwrap(); assert_eq!(entry.0, 2); - assert_eq!(entry.1, arena.allocated_bytes()) + assert_eq!(entry.1, arena.allocated_bytes()); } } diff --git a/third-party/rust/starlark-rust/starlark/src/values/layout/heap.rs b/third-party/rust/starlark-rust/starlark/src/values/layout/heap.rs index 0fe3a284b10..d2a63789b32 100644 --- a/third-party/rust/starlark-rust/starlark/src/values/layout/heap.rs +++ b/third-party/rust/starlark-rust/starlark/src/values/layout/heap.rs @@ -133,6 +133,13 @@ impl FrozenHeapRef { self.0.arena.allocated_bytes() } + /// Number of bytes allocated by the heap but not filled. + /// Note that these bytes will _never_ be filled as no further allocations can + /// be made on this heap (it has been sealed). + pub fn available_bytes(&self) -> usize { + self.0.arena.available_bytes() + } + /// Obtain a summary of how much memory is currently allocated by this heap. /// Doesn't include the heaps it keeps alive by reference. pub fn allocated_summary(&self) -> HeapSummary { @@ -204,6 +211,11 @@ impl FrozenHeap { self.arena.allocated_bytes() } + /// Number of bytes allocated by the heap but not yet filled. + pub fn available_bytes(&self) -> usize { + self.arena.available_bytes() + } + /// Obtain a summary of how much memory is currently allocated by this heap. pub fn allocated_summary(&self) -> HeapSummary { self.arena.allocated_summary() @@ -289,6 +301,11 @@ impl Heap { self.arena.borrow().allocated_bytes() } + /// Number of bytes allocated by the heap but not yet filled. + pub fn available_bytes(&self) -> usize { + self.arena.borrow().available_bytes() + } + /// Only those allocated on the inline heap (mostly strings) pub(crate) fn allocated_bytes_inline(&self) -> usize { self.arena.borrow().allocated_bytes_inline()