1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-09 03:50:45 +00:00

LibJS: Fast path for Increment of Int32 value in bytecode interpreter

5% speed-up on Kraken/ai-astar.js in interpreter mode. :^)
This commit is contained in:
Andreas Kling 2024-01-27 20:51:11 +01:00
parent 9fcd6776cf
commit 9326ded5a4

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021-2024, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -1045,7 +1045,18 @@ ThrowCompletionOr<void> Return::execute_impl(Bytecode::Interpreter& interpreter)
ThrowCompletionOr<void> Increment::execute_impl(Bytecode::Interpreter& interpreter) const
{
auto& vm = interpreter.vm();
auto old_value = TRY(interpreter.accumulator().to_numeric(vm));
auto old_value = interpreter.accumulator();
// OPTIMIZATION: Fast path for Int32 values.
if (old_value.is_int32()) {
auto integer_value = old_value.as_i32();
if (integer_value != NumericLimits<i32>::max()) [[likely]] {
interpreter.accumulator() = Value { integer_value + 1 };
return {};
}
}
old_value = TRY(old_value.to_numeric(vm));
if (old_value.is_number())
interpreter.accumulator() = Value(old_value.as_double() + 1);