mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:48:12 +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
|
@ -42,6 +42,10 @@ PrimitiveString* js_string(Heap& heap, String string)
|
|||
{
|
||||
if (string.is_empty())
|
||||
return &heap.vm().empty_string();
|
||||
|
||||
if (string.length() == 1 && (u8)string.characters()[0] < 0x80)
|
||||
return &heap.vm().single_ascii_character_string(string.characters()[0]);
|
||||
|
||||
return heap.allocate_without_global_object<PrimitiveString>(move(string));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue