Skip to content

Commit

Permalink
FrozenHeap always interns strings
Browse files Browse the repository at this point in the history
Summary:
During starlark execution, strings can be created and destroyed, and the normal `Heap` should not be interning strings if it can help it.

When we freeze heaps, though, strings no longer change. If we intern them (into their respective frozen heaps), we can gain some retained memory back.

Reviewed By: stepancheg

Differential Revision: D66388344

fbshipit-source-id: e2f5bcc4a6669649e99cbc9099e8f6a8925988dc
  • Loading branch information
Jeremy Braun authored and facebook-github-bot committed Dec 4, 2024
1 parent 760df74 commit e5b166a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions starlark/src/values/layout/heap/heap_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,13 @@ impl FrozenHeap {
}
}

/// Allocate a string on this heap. Be careful about the warnings
/// around [`FrozenValue`].
/// Allocate a string on this heap. Be careful about the warnings around
/// [`FrozenValue`].
///
/// Since the heap is frozen, we always prefer to intern the string in order
/// to deduplicate it and save some memory.
pub fn alloc_str(&self, x: &str) -> FrozenStringValue {
self.alloc_str_impl(x, StarlarkStr::UNINIT_HASH)
self.alloc_str_intern(x)
}

/// Intern string.
Expand Down

0 comments on commit e5b166a

Please sign in to comment.