Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Code adjustments in unique() generator #786

Closed
wants to merge 3 commits into from

Conversation

vlakoff
Copy link
Contributor

@vlakoff vlakoff commented Nov 28, 2015

Highlights:

  • When unique value found, serialize once instead of twice. If unique values are likely to be found on first try, this results in twice less serialize calls. Refs Serialized $res key #749.
  • Use isset() instead of array_key_exists(), the former being a language construct and not a function, it is significantly faster. This change also allows code simplification by removing the "intermediary index creation" step at beginning of method. Refs Improve unique generator performance #491.

@fzaninotto
Copy link
Owner

Did you benchmark the speedup?

@vlakoff
Copy link
Contributor Author

vlakoff commented Nov 30, 2015

Just did some quick xdebug profiling, and the speedup about serialize() and array_key_exists() appears to be rather insignificant… (still, it can't harm, let's call this a little code polishing ;)

Though, the call_user_func_array() calls are very costly, they are a bottleneck (roughly 10% execution time of my test script, top 5 of most costly functions). They can be avoided as Laravel does, and I think the added bit of complexity is worth it.

After this PR is merged (if you wish so ;) I'll submit an other one to avoid calling this hugely costly call_user_func_array().

@fzaninotto
Copy link
Owner

If you submit a perf patch, you must be able to prove that it works. So please provide an execution time before/after on a series of calls, describing the conditions of the test. If the gain is significant, I'll merge. Otherwise, I won't. It's as simple as that.

@vlakoff vlakoff changed the title Optimize unique() generator Code adjustments in unique() generator Nov 30, 2015
@vlakoff
Copy link
Contributor Author

vlakoff commented Nov 30, 2015

Please consider this PR as just some code adjustments, merge it or not, up to you :)

If I submit a PR about call_user_func_array(), I'll provide some numbers along.

@vlakoff vlakoff force-pushed the unique branch 2 times, most recently from defab9e to 8494788 Compare January 23, 2016 05:05
@vlakoff
Copy link
Contributor Author

vlakoff commented Jan 23, 2016

Rebased and simplified a little bit.

Despite the diffs, the changes are really straightforward. It just brings a cleaner code.

Could you please merge or close? your pick :)

@fzaninotto fzaninotto closed this Jan 26, 2016
@vlakoff vlakoff deleted the unique branch January 26, 2016 21:07
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.

2 participants