LibJS: Add SetGlobal bytecode instruction for cached global writes

Before this change, setting a global would end up as SetLexicalBinding.
That instruction always failed to cache the access if the global was a
property of the global object.

1.14x speedup on Octane/earley-boyer.js
2.04x speedup on MicroBench/for-of.js

Note that MicroBench/for-of.js was more of a "set global" benchmark
before this. After this change, it's actually a for..of benchmark. :^)
This commit is contained in:
Andreas Kling 2025-05-01 23:58:38 +02:00 committed by Andreas Kling
parent de6df6f403
commit ad7c1e147f
Notes: github-actions[bot] 2025-05-03 23:59:49 +00:00
4 changed files with 134 additions and 1 deletions

View file

@ -892,7 +892,11 @@ void Generator::emit_set_variable(JS::Identifier const& identifier, ScopedOperan
if (initialization_mode == Bytecode::Op::BindingInitializationMode::Initialize) {
emit<Bytecode::Op::InitializeLexicalBinding>(identifier_index, value);
} else if (initialization_mode == Bytecode::Op::BindingInitializationMode::Set) {
emit<Bytecode::Op::SetLexicalBinding>(identifier_index, value);
if (identifier.is_global()) {
emit<Bytecode::Op::SetGlobal>(identifier_index, value, next_global_variable_cache());
} else {
emit<Bytecode::Op::SetLexicalBinding>(identifier_index, value);
}
}
} else if (environment_mode == Bytecode::Op::EnvironmentMode::Var) {
if (initialization_mode == Bytecode::Op::BindingInitializationMode::Initialize) {