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

@@ -706,6 +706,7 @@ endop
op NewObject < Instruction
@nothrow
m_dst: Operand
m_cache_index: u32
endop
op NewObjectWithNoPrototype < Instruction
@@ -1063,3 +1064,18 @@ op Yield < Instruction
m_value: Operand
endop
op CacheObjectShape < Instruction
@nothrow
m_object: Operand
m_cache_index: u32
endop
op InitObjectLiteralProperty < Instruction
@nothrow
m_object: Operand
m_property: PropertyKeyTableIndex
m_src: Operand
m_shape_cache_index: u32
m_property_slot: u32
endop