Skip to content

Zend: add_function_array() fast paths for an empty operand. - #24247

Open
devnexen wants to merge 2 commits into
php:masterfrom
devnexen:add_function_array_optim
Open

devnexen wants to merge 2 commits into
php:masterfrom
devnexen:add_function_array_optim

Conversation

@devnexen

Copy link
Copy Markdown
Member

Skip the duplicate and merge when either operand is empty, unless sharing would change the internal pointer or next free index.

Skip the duplicate and merge when either operand is empty, unless
sharing would change the internal pointer or next free index.
@devnexen

Copy link
Copy Markdown
Member Author

Some numbers, release build without opcache, best of 7 runs, in ms.

8 elements, 1M iterations:

hash before hash after list before list after
$a + [] 36.3 6.2 26.8 6.2
[] + $a 50.2 7.2 46.5 6.6
$x = []; $x += $a 51.5 10.2 47.4 9.7
$a + $b 86.0 89.1 44.3 44.7

100 elements, 100k iterations:

hash before hash after list before list after
$a + [] 24.8 0.6 9.9 0.6
[] + $a 66.9 0.8 42.6 0.7
$x = []; $x += $a 63.6 1.0 42.6 1.0
$a + $b 83.4 84.7 26.1 26.4

$a + $b is there as a control, the difference is noise on my machine.

@devnexen
devnexen marked this pull request as ready for review October 10, 2026 20:20
Comment thread Zend/zend_operators.c
/* $a += $a */
return;
}
if (zend_hash_num_elements(Z_ARRVAL_P(op2)) == 0 &&

@ndossche ndossche Oct 11, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditions are unintuitive (talking about the entire nInternalPointer & free element conditions), can you add comments explaining them?

Comment thread Zend/zend_operators.c
Comment on lines +1219 to +1220
src->nInternalPointer == 0 &&
src->nNextFreeElement == next_free) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed code uses a mix of tabs and spaces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants