You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
since the hooks are stored in a static $hooks property on the Base class, each child class shares the same property.
When instantiating 3 childclasses, all 3 childclasses will register the hooks in it's base class. Effectively duplicating the code which needs to run.
In our case, we had 200 child classes, so 200 hooks were registered in the base class. When retrieving a property, and thus running through the registered hooks of getAttribute, this caused quite a bit of performance loss and also a stack trace too deep.
I've fixed in on our side via:
useSofa\Eloquence\MetableasMetableBase;
class Base {
use MetableBase {
MetableBase::bootMetable as metableBootMetable;
}
/** @var bool */privatestatic$isMetableBooted = false;
publicstaticfunctionbootMetable(): void
{
if (self::$isMetableBooted) {
return;
}
self::$isMetableBooted = true;
static::metableBootMetable();
}
but it might be worthwhile to backport that fix it here
Regards,
The text was updated successfully, but these errors were encountered:
Hey,
Thanks for these great packages.
I found something to what might be seen as a bug when registering the hooks in
eloquence-metable
.when working with the following structure:
while instantiating the child classes, each of 'm runs bootMetable. Which ofcourse makes sense given Laravel's bootTraits nature.
The problem arises in
sofa/hookable/src/Hookable.php:27
since the hooks are stored in a static
$hooks
property on theBase
class, each child class shares the same property.When instantiating 3 childclasses, all 3 childclasses will register the hooks in it's base class. Effectively duplicating the code which needs to run.
In our case, we had 200 child classes, so 200 hooks were registered in the base class. When retrieving a property, and thus running through the registered hooks of
getAttribute
, this caused quite a bit of performance loss and also a stack trace too deep.I've fixed in on our side via:
but it might be worthwhile to backport that fix it here
Regards,
The text was updated successfully, but these errors were encountered: