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
Every access of an attribute on an Eloquent model results in the following (simplified) general flow:
magic __get -> getAttributeValue -> check if cast or mutator method is required -> call cast or mutator method -> return.
These values are not cached and are re-casted/converted every time the attribute is accessed. Given that it is common to access a model’s attribute several times through out a single request, there is potentially some performance to be gained but not having to repeatedly recast the value; the flip side is that if an attribute is only accessed once, the value have have been cached unnecessarily.
Premilinary testing with caching the converted attribute values on Beatmap and Beatmapset on the beatmapsets/search endpoint yields about a 6% increase in throughput (completely replacing Laravel’s casting is a >15% improvement).
While it is possible to read a model’s converted attribute value into a variable and pass that around, it is simply not practical and unwieldy to constantly ferry around the required variables across the various layers of the application. We could group multiple variables into DTOs and pass those around instead, but then we’d have to be able to remap them back to Eloquent models, at which point we’re approaching the realm of being better off having proper domain models using a more straightforward data mapper, rather than Laravel’s ORM.
The text was updated successfully, but these errors were encountered:
Every access of an attribute on an Eloquent model results in the following (simplified) general flow:
magic
__get
->getAttributeValue
-> check if cast or mutator method is required -> call cast or mutator method -> return.These values are not cached and are re-casted/converted every time the attribute is accessed. Given that it is common to access a model’s attribute several times through out a single request, there is potentially some performance to be gained but not having to repeatedly recast the value; the flip side is that if an attribute is only accessed once, the value have have been cached unnecessarily.
Premilinary testing with caching the converted attribute values on
Beatmap
andBeatmapset
on thebeatmapsets/search
endpoint yields about a 6% increase in throughput (completely replacing Laravel’s casting is a >15% improvement).While it is possible to read a model’s converted attribute value into a variable and pass that around, it is simply not practical and unwieldy to constantly ferry around the required variables across the various layers of the application. We could group multiple variables into DTOs and pass those around instead, but then we’d have to be able to remap them back to Eloquent models, at which point we’re approaching the realm of being better off having proper domain models using a more straightforward data mapper, rather than Laravel’s ORM.
The text was updated successfully, but these errors were encountered: