Improve performance for hydrated collections #2749
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)