LibJS: Move computation out of the ECMAScriptFunctionObject constructor

We were doing way too much computation every time an ESFO was
instantiated. This was particularly sad, since the results of these
computations were identical every time!

This patch adds a new SharedFunctionInstanceData object that gets
shared between all instances of an ESFO instantiated from some kind of
AST FunctionNode.

~5% speedup on Speedometer 2.1 :^)
This commit is contained in:
Andreas Kling 2025-04-08 00:45:27 +02:00 committed by Andreas Kling
parent 4209b18b88
commit 2a9b6f1d97
Notes: github-actions[bot] 2025-04-08 16:53:53 +00:00
7 changed files with 367 additions and 258 deletions

View file

@ -426,7 +426,7 @@ GC::Ref<FunctionEnvironment> new_function_environment(ECMAScriptFunctionObject&
env->set_function_object(function);
// 3. If F.[[ThisMode]] is lexical, set env.[[ThisBindingStatus]] to lexical.
if (function.this_mode() == ECMAScriptFunctionObject::ThisMode::Lexical)
if (function.this_mode() == ThisMode::Lexical)
env->set_this_binding_status(FunctionEnvironment::ThisBindingStatus::Lexical);
// 4. Else, set env.[[ThisBindingStatus]] to uninitialized.
else
@ -555,7 +555,7 @@ ThrowCompletionOr<Value> perform_eval(VM& vm, Value x, CallerMode strict_caller,
in_method = this_function_environment_record.has_super_binding();
// iv. If F.[[ConstructorKind]] is derived, set inDerivedConstructor to true.
if (function.constructor_kind() == ECMAScriptFunctionObject::ConstructorKind::Derived)
if (function.constructor_kind() == ConstructorKind::Derived)
in_derived_constructor = true;
// v. Let classFieldInitializerName be F.[[ClassFieldInitializerName]].