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:
Andreas Kling 2026-01-09 18:55:00 +01:00 committed by Andreas Kling
parent b37ee5d356
commit 505fe0a977
Notes: github-actions[bot] 2026-01-09 23:57:41 +00:00
7 changed files with 117 additions and 2 deletions

View file

@ -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;