mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-30 13:19:47 +00:00
LibJS: Let the VM cache an empty ("") PrimitiveString
Empty string is extremely common and we can avoid a lot of heap churn by simply caching one in the VM. Primitive strings are immutable anyway so there is no observable behavior change outside of fewer collections.
This commit is contained in:
@@ -38,6 +38,7 @@ NonnullRefPtr<VM> VM::create()
|
||||
VM::VM()
|
||||
: m_heap(*this)
|
||||
{
|
||||
m_empty_string = m_heap.allocate_without_global_object<PrimitiveString>(String::empty());
|
||||
#define __JS_ENUMERATE(SymbolName, snake_name) \
|
||||
m_well_known_symbol_##snake_name = js_symbol(*this, "Symbol." #SymbolName, false);
|
||||
JS_ENUMERATE_WELL_KNOWN_SYMBOLS
|
||||
@@ -86,6 +87,7 @@ VM::InterpreterExecutionScope::~InterpreterExecutionScope()
|
||||
|
||||
void VM::gather_roots(HashTable<Cell*>& roots)
|
||||
{
|
||||
roots.set(m_empty_string);
|
||||
if (m_exception)
|
||||
roots.set(m_exception);
|
||||
for (auto* interpreter : m_interpreters)
|
||||
|
||||
Reference in New Issue
Block a user