mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-18 18:00:31 +00:00
LibJS: Add shape caching for object literal instantiation
When a function creates object literals with simple property names, we now cache the resulting shape after the first instantiation. On subsequent calls, we create the object with the cached shape directly and write property values at their known offsets. This avoids repeated shape transitions and property offset lookups for a common JavaScript pattern. The optimization uses two new bytecode instructions: - CacheObjectShape: Captures the final shape after object construction - InitObjectLiteralProperty: Writes properties using cached offsets Only "simple" object literals are optimized (string literal keys with simple value expressions). Complex cases like computed properties, getters/setters, and spread elements use the existing slow path. 3.4x speedup on a microbenchmark that repeatedly instantiates an object literal with 26 properties. Small progressions on various benchmarks.
This commit is contained in:
parent
b37ee5d356
commit
505fe0a977
Notes:
github-actions[bot]
2026-01-09 23:57:41 +00:00
Author: https://github.com/awesomekling
Commit: 505fe0a977
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7406
7 changed files with 117 additions and 2 deletions
|
|
@ -27,6 +27,7 @@ Executable::Executable(
|
|||
size_t number_of_property_lookup_caches,
|
||||
size_t number_of_global_variable_caches,
|
||||
size_t number_of_template_object_caches,
|
||||
size_t number_of_object_shape_caches,
|
||||
size_t number_of_registers,
|
||||
Strict strict)
|
||||
: bytecode(move(bytecode))
|
||||
|
|
@ -42,6 +43,7 @@ Executable::Executable(
|
|||
property_lookup_caches.resize(number_of_property_lookup_caches);
|
||||
global_variable_caches.resize(number_of_global_variable_caches);
|
||||
template_object_caches.resize(number_of_template_object_caches);
|
||||
object_shape_caches.resize(number_of_object_shape_caches);
|
||||
}
|
||||
|
||||
Executable::~Executable() = default;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue