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

Refactor call frame access to avoid panic checks #3888

Closed raskad closed 5 days ago

raskad commented 6 days ago

This PR slightly changes how we store and access call frames in the vm. In addition to the frames stack, there is now a frame field that always holds the current call frame. The main reason for this is, so that we can avoid panic checks in critical paths.

I also removed some duplicate calls to Vm::frame and Vm::fram_mut and grouped them where possible. This should not be that relevant anymore, since now it's just a field access.

Here two graphs to visualize the change. These are running in dev profile so functions are visible. Here the bigger impact seems to actually be the deref of the frames vec, but I'm not sure if the actual cost in release looks different.

Before: image

After: image

And here some benchmarks. I did not run them multiple times, the impact seems a bit high to me:

Before:

RESULT Richards 55.7
RESULT DeltaBlue 57.8
RESULT Crypto 67.7
RESULT RayTrace 187
RESULT EarleyBoyer 174
RESULT RegExp 60.4
RESULT Splay 192
RESULT NavierStokes 155
SCORE 103

After:

RESULT Richards 59.1
RESULT DeltaBlue 59.7
RESULT Crypto 72.5
RESULT RayTrace 197
RESULT EarleyBoyer 182
RESULT RegExp 60.0
RESULT Splay 189
RESULT NavierStokes 172
SCORE 108
github-actions[bot] commented 6 days 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%