Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance for hydrated collections #2749

Merged
merged 1 commit into from
Oct 31, 2024
Merged

Conversation

inserve-paul
Copy link
Contributor

After profiling our application it appeared that a lot of time of a request was wasted in the PermissionRegistrar. When creating a collection of Permission objects the array_map method is used to create these objects from the items in cache. However everytime the newInstance method is called on the permission instance.

In this PR I've replaced this call by using the native clone method, this performs about 3 times faster!

For e.g. in our application we have about 400 permissions; which takes +/- 18ms to create the hydrated permission collection. By using the native clone method it only takes 6ms. (Executed on a dev environment, without xDebug and xhProf enabled)

@drbyte
Copy link
Collaborator

drbyte commented Oct 31, 2024

Thanks!

@drbyte drbyte merged commit 7615c44 into spatie:main Oct 31, 2024
33 checks passed
erikn69 added a commit to erikn69/laravel-permission that referenced this pull request Nov 8, 2024
drbyte pushed a commit that referenced this pull request Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants