summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/ScriptFunction.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-06-07 15:19:48 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-07 18:11:59 +0200
commit4ba2eb8fe531094ed783c0267a9603c91dfc645e (patch)
treec257fb9eac78185140a945d12fa833acade51687 /Userland/Libraries/LibJS/Runtime/ScriptFunction.cpp
parent7cbe4daa7ca7ceb4b41d0787445a5372436d85ad (diff)
downloadserenity-4ba2eb8fe531094ed783c0267a9603c91dfc645e.zip
LibJS: Cache generated bytecode for ScriptFunction
It's silly to generate new bytecode every time you call a function. Let's just cache the code instead. :^)
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/ScriptFunction.cpp')
-rw-r--r--Userland/Libraries/LibJS/Runtime/ScriptFunction.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ScriptFunction.cpp b/Userland/Libraries/LibJS/Runtime/ScriptFunction.cpp
index 9447544d40..3a4e83f4cb 100644
--- a/Userland/Libraries/LibJS/Runtime/ScriptFunction.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ScriptFunction.cpp
@@ -151,13 +151,15 @@ Value ScriptFunction::execute_function_body()
if (bytecode_interpreter) {
prepare_arguments();
- auto block = Bytecode::Generator::generate(m_body);
- VERIFY(block);
- if constexpr (JS_BYTECODE_DEBUG) {
- dbgln("Compiled Bytecode::Block for function '{}':", m_name);
- block->dump();
+ if (!m_bytecode_block) {
+ m_bytecode_block = Bytecode::Generator::generate(m_body);
+ VERIFY(m_bytecode_block);
+ if constexpr (JS_BYTECODE_DEBUG) {
+ dbgln("Compiled Bytecode::Block for function '{}':", m_name);
+ m_bytecode_block->dump();
+ }
}
- return bytecode_interpreter->run(*block);
+ return bytecode_interpreter->run(*m_bytecode_block);
} else {
OwnPtr<Interpreter> local_interpreter;
ast_interpreter = vm.interpreter_if_exists();