Improve performance of CastPropertiesDataPipe by using hash lookups instead of ->first #721
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.
Hi Spatie developers.
I was running into some performance issues when creating thousands of data objects from array payloads, which lead me to run the xdebug profiler.
I setup a local benchmark where I created and validated 10k data objects using the
::collect
method, the data class has 18 properties, most of which have casts in place (enums, Carbon, and other custom casts)I noticed from my xdebug profile results that the closure in the deleted line is ran a whopping 1.710.000 times. By replacing with the new line, I managed to reduce my crude benchmark from an 11 seconds runtime, to 6.5 seconds. I thought you would be interested in this finding.
Unfortunately I am not very well versed in this project, and I am a bit uncertain if the
DataClass:properties
collection is always keyed by the data property name, but I am hoping we can collaborate into merging either this change, or a similar change, that introduces a hash lookup instead of the->first
method currently in place.