mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 05:47:34 +00:00
LibJS: Give VM a cache of single-ASCII-character PrimitiveString
A large number of JS strings are a single ASCII character. This patch adds a 128-entry cache for those strings to the VM. The cost of the cache is 1536 byte of GC heap (all in same block) + 2304 bytes malloc. This avoids a lot of GC heap allocations, and packing all of these in the same heap block is nice for fragmentation as well.
This commit is contained in:
parent
5c2520e6b2
commit
619cd613d0
3 changed files with 17 additions and 0 deletions
|
@ -47,6 +47,10 @@ VM::VM()
|
|||
: m_heap(*this)
|
||||
{
|
||||
m_empty_string = m_heap.allocate_without_global_object<PrimitiveString>(String::empty());
|
||||
for (size_t i = 0; i < 128; ++i) {
|
||||
m_single_ascii_character_strings[i] = m_heap.allocate_without_global_object<PrimitiveString>(String::format("%c", i));
|
||||
}
|
||||
|
||||
#define __JS_ENUMERATE(SymbolName, snake_name) \
|
||||
m_well_known_symbol_##snake_name = js_symbol(*this, "Symbol." #SymbolName, false);
|
||||
JS_ENUMERATE_WELL_KNOWN_SYMBOLS
|
||||
|
@ -96,6 +100,9 @@ VM::InterpreterExecutionScope::~InterpreterExecutionScope()
|
|||
void VM::gather_roots(HashTable<Cell*>& roots)
|
||||
{
|
||||
roots.set(m_empty_string);
|
||||
for (auto* string : m_single_ascii_character_strings)
|
||||
roots.set(string);
|
||||
|
||||
if (m_exception)
|
||||
roots.set(m_exception);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue