-
Notifications
You must be signed in to change notification settings - Fork 8k
Improve performance of array_map() #18158
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
Conversation
878649a to
07a4216
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks correct to me.
| } | ||
|
|
||
| fci.retval = &result; | ||
| fci.param_count = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason this isn't moved up so that the two HT_IS_PACKED(input) branches can be joined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason, I'll merge them.
| if (HT_IS_PACKED(input)) { | ||
| uint32_t undefs = 0; | ||
| ZEND_HASH_FILL_PACKED(output) { | ||
| for (zval *cur = input->arPacked, *end = input->arPacked + input->nNumUsed; cur != end; cur++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not using ZEND_HASH_PACKED_FOREACH_VAL() to avoid skipping undef values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a comment, and possibly a test even to make sure this doesn't get changed in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a comment now. Adding a test was not necessary as 3 tests already test this.
The refcounting and destruction is not necessary because zend_call_function will make a copy anyway. And zend_call_function only returns FAILURE if EG(active) is false in which case array_map shouldn't have been called in the first place.
b1b6963 to
846900b
Compare
The refcounting and destruction is not necessary because zend_call_function will make a copy anyway. And zend_call_function only returns FAILURE if EG(active) is false in which case array_map shouldn't have been called in the first place.
This also adds a fast path for packed arrays (even with holes). By separating the paths of packed/hashed arrays the hashed array iteration is very very slightly faster as well but not by much.
For this script:
On an intel i7-1185G7: