LibJS: Cache the shape for normal ECMAScriptFunctionObject prototypes

Instead of creating a unique new prototype shape every time a function
object is instantiated, we now keep one cached with the intrinsics.

This avoids a whole lot of shape allocations, reducing GC pressure.
This commit is contained in:
Andreas Kling
2024-09-26 17:05:56 +02:00
committed by Andreas Kling
parent 795471ce31
commit 749cf2d1b5
3 changed files with 15 additions and 2 deletions

View File

@@ -354,8 +354,8 @@ void ECMAScriptFunctionObject::initialize(Realm& realm)
Object* prototype = nullptr;
switch (m_kind) {
case FunctionKind::Normal:
prototype = Object::create_prototype(realm, realm.intrinsics().object_prototype());
MUST(prototype->define_property_or_throw(vm.names.constructor, { .value = this, .writable = true, .enumerable = false, .configurable = true }));
prototype = Object::create_with_premade_shape(realm.intrinsics().new_function_object_prototype_shape());
prototype->put_direct(realm.intrinsics().new_function_object_prototype_constructor_offset(), this);
break;
case FunctionKind::Generator:
// prototype is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png)