Skip to content
This repository was archived by the owner on Feb 16, 2022. It is now read-only.

Significant performance improvement by bypassing Eloquent model magic #97

Merged

Conversation

simonworkhouse
Copy link

When accessing Eloquent model attributes via $model->getAttribute(...) or $model->attribute, Eloquent will check if the attribute needs to be cast or mutated. This adds significant processing time when accessing attributes so instead we bypass this by calling $model->getAttributes()['attribute'] and casting it ourselves.

when attaching attribute relationships to models.

When accessing Eloquent model attributes via
`$model->getAttribute(...)` or `$model->attribute`, Eloquent will check
if the attribute needs to be cast or mutated. This adds significant
processing time when accessing attributes so instead we bypass this by
calling `$model->getAttributes()['attribute']` and casting it ourselves.
@simonworkhouse
Copy link
Author

Sorry, this probably should have been a draft pull request as there is probably some discussion to be had whether or not we can ignore considerations for changes in casts or potential mutators.

@simonworkhouse
Copy link
Author

@Omranic Any chance that this will be looked at?

@batFormat
Copy link

@Omranic, will be looked at?

@Omranic Omranic merged commit 87f20b3 into rinvex:develop Dec 25, 2019
@Omranic
Copy link
Member

Omranic commented Dec 25, 2019

Merged, thank you! Further performance improvements, and / or test suites will be appreciated :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants