boa-dev / boa

Boa is an embeddable and experimental Javascript engine written in Rust. Currently, it has support for some of the language.
MIT License
4.82k stars 385 forks source link

Combine `HasProperty` and `Get` operations when possible #3883

Closed raskad closed 1 week ago

raskad commented 1 week ago

This PR creates a new object operation that combines the HasProperty and Get operations.

In some cases in the spec HasProperty and Get are called on an object, with the same arguments, directly following each other. Both operations boil down to (in most cases) [[GetOwnProperty]], just that HasProperty does not return the value. To avoid duplicating the exact same operations we can combine both operations.

I have some Flame Graphs from a GetName operation to visualize the benefit:

Before: image After: image

I also ran the benchmarks:

Before:

RESULT Richards 54.3
RESULT DeltaBlue 58.2
RESULT Crypto 68.4
RESULT RayTrace 186
RESULT EarleyBoyer 170
RESULT RegExp 58.6
RESULT Splay 195
RESULT NavierStokes 159
SCORE 103

After:

RESULT Richards 55.1
RESULT DeltaBlue 59.6
RESULT Crypto 68.1
RESULT RayTrace 187
RESULT EarleyBoyer 176
RESULT RegExp 58.5
RESULT Splay 195
RESULT NavierStokes 160
SCORE 104
github-actions[bot] commented 1 week ago

Test262 conformance changes

Test result main count PR count difference
Total 50,213 50,213 0
Passed 42,981 42,981 0
Ignored 1,411 1,411 0
Failed 5,821 5,821 0
Panics 0 0 0
Conformance 85.60% 85.60% 0.00%
jedel1043 commented 1 week ago

Really nice optimization! I'm seeing that all our usages of the new method are made internally, so I was curious if we could set up inline caching manually to optimise the calls even more.

EDIT: cc @HalidOdat

HalidOdat commented 1 week ago

Yeah that was one of the things that could be optimized, though I didn't find a good way of doing it, one potentially viable idea I had was to have a global hash table on the context (with limited entries).