optimized apply() by moving $operators into a static array where possible #18
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.
Moved most of $operators -array's content into a static variable, so the array doesn't need to be defined on each call to apply().
Operators for
var
,missing
andmissing_some
were crudely moved into the if/elseif/else structure as those neededuse ($data)
. Their implementation in the if/elseif/else could probably be prettier.Rationale for this change was performance. In our application we needed to run n-amounts of apply() calls to potentially thousands, sometimes tens of thousands of arrays, and it quickly became apparent that there was some room for optimization. After moving the $operators as static, the apply() -calls only used 1/3rd of the time they used to.
In my (crude) tests, with 100k loops for these test logics and data
The "static operations" version performed in 1/4th of the time the current 1.5.1 version does. This was with opcache enabled on php.