LibJS: Lazily instantiate "prototype" field on ECMAScriptFunctionObject

This field is rarely accessed but we were creating it for every single
script function instantiated.

It's a little awkward but the same optimization can be found in other
engines, so it's nothing crazy.

This avoids creating roughly 80,000 objects on my x.com home feed.
This commit is contained in:
Andreas Kling
2025-12-16 19:20:59 -06:00
committed by Andreas Kling
parent 941336505c
commit cbe75f8251
Notes: github-actions[bot] 2025-12-17 18:51:45 +00:00
4 changed files with 21 additions and 8 deletions

View File

@@ -117,6 +117,8 @@ private:
PrivateEnvironment* private_environment,
Object& prototype);
virtual ThrowCompletionOr<Optional<PropertyDescriptor>> internal_get_own_property(PropertyKey const&) const override;
virtual bool is_strict_mode() const override { return shared_data().m_strict; }
ThrowCompletionOr<Value> ordinary_call_evaluate_body(VM&, ExecutionContext&);
@@ -145,6 +147,8 @@ private:
};
ClassData& ensure_class_data() const;
mutable OwnPtr<ClassData> m_class_data;
mutable bool m_may_need_lazy_prototype_instantiation { false };
};
template<>