mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:37:34 +00:00
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. :^)
This commit is contained in:
parent
7cbe4daa7c
commit
4ba2eb8fe5
2 changed files with 9 additions and 6 deletions
|
@ -151,13 +151,15 @@ Value ScriptFunction::execute_function_body()
|
||||||
|
|
||||||
if (bytecode_interpreter) {
|
if (bytecode_interpreter) {
|
||||||
prepare_arguments();
|
prepare_arguments();
|
||||||
auto block = Bytecode::Generator::generate(m_body);
|
if (!m_bytecode_block) {
|
||||||
VERIFY(block);
|
m_bytecode_block = Bytecode::Generator::generate(m_body);
|
||||||
if constexpr (JS_BYTECODE_DEBUG) {
|
VERIFY(m_bytecode_block);
|
||||||
dbgln("Compiled Bytecode::Block for function '{}':", m_name);
|
if constexpr (JS_BYTECODE_DEBUG) {
|
||||||
block->dump();
|
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 {
|
} else {
|
||||||
OwnPtr<Interpreter> local_interpreter;
|
OwnPtr<Interpreter> local_interpreter;
|
||||||
ast_interpreter = vm.interpreter_if_exists();
|
ast_interpreter = vm.interpreter_if_exists();
|
||||||
|
|
|
@ -47,6 +47,7 @@ private:
|
||||||
FlyString m_name;
|
FlyString m_name;
|
||||||
NonnullRefPtr<Statement> m_body;
|
NonnullRefPtr<Statement> m_body;
|
||||||
const Vector<FunctionNode::Parameter> m_parameters;
|
const Vector<FunctionNode::Parameter> m_parameters;
|
||||||
|
OwnPtr<Bytecode::Block> m_bytecode_block;
|
||||||
ScopeObject* m_parent_scope { nullptr };
|
ScopeObject* m_parent_scope { nullptr };
|
||||||
i32 m_function_length { 0 };
|
i32 m_function_length { 0 };
|
||||||
bool m_is_strict { false };
|
bool m_is_strict { false };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue