Skip to content

Improve array_reduce() consume carry#21340

Open
drealecs wants to merge 2 commits intophp:masterfrom
drealecs:improve-array-reduce-consume-carry
Open

Improve array_reduce() consume carry#21340
drealecs wants to merge 2 commits intophp:masterfrom
drealecs:improve-array-reduce-consume-carry

Conversation

@drealecs
Copy link

@drealecs drealecs commented Mar 4, 2026

Related to #8283

For some callback operations, it is safe to consume/reuse a value passed as a parameter instead of copying it first.
This PR adds a generic internal mechanism for that (zend_fcall_info.consume_params) and applies it to array_reduce() carry handling.

This reduces copy-on-write churn and significantly improves array_reduce() performance for mutable accumulator patterns, while keeping userland semantics unchanged.

The same mechanism can be used in other callback-heavy paths in follow-up changes.

@drealecs drealecs force-pushed the improve-array-reduce-consume-carry branch 2 times, most recently from 86f212d to 2f9aa58 Compare March 4, 2026 17:24
@drealecs drealecs changed the title Draft: Improve array_reduce() consume carry Improve array_reduce() consume carry Mar 4, 2026
@drealecs drealecs force-pushed the improve-array-reduce-consume-carry branch from 2f9aa58 to 3299db5 Compare March 4, 2026 18:55
@TimWolla
Copy link
Member

TimWolla commented Mar 4, 2026

Can you provide the benchmark you used to verify this improves the situation?

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.

2 participants