LibJS: Make GetById cache polymorphic

Instead of monomorphic (1 shape), GetById inline caches are now
polymorphic (4 shapes).

This improves inline cache hit rates greatly on most web JavaScript.
For example, Speedometer 2.1 sees 88% -> 97% cache hit rate improvement.

1.71x speedup on MicroBench/pic-get-own.js
1.82x speedup on MicroBench/pic-get-pchain.js
This commit is contained in:
Andreas Kling 2025-05-06 13:16:44 +02:00 committed by Andreas Kling
parent 678c15a06a
commit a677d96b8f
Notes: github-actions[bot] 2025-05-06 22:28:14 +00:00
2 changed files with 59 additions and 43 deletions

View file

@ -23,11 +23,16 @@
namespace JS::Bytecode {
// Represents one polymorphic inline cache used for property lookups.
struct PropertyLookupCache {
WeakPtr<Shape> shape;
Optional<u32> property_offset;
WeakPtr<Object> prototype;
WeakPtr<PrototypeChainValidity> prototype_chain_validity;
static constexpr size_t max_number_of_shapes_to_remember = 4;
struct Entry {
WeakPtr<Shape> shape;
Optional<u32> property_offset;
WeakPtr<Object> prototype;
WeakPtr<PrototypeChainValidity> prototype_chain_validity;
};
AK::Array<Entry, max_number_of_shapes_to_remember> entries;
};
struct GlobalVariableCache : public PropertyLookupCache {