Skip to content

[PFA 4/n] Optimize constant pre-bound arguments - #22829

Merged
arnaud-lb merged 5 commits into
php:masterfrom
arnaud-lb:partials-const-arg-opt
Jul 27, 2026
Merged

[PFA 4/n] Optimize constant pre-bound arguments #22829
arnaud-lb merged 5 commits into
php:masterfrom
arnaud-lb:partials-const-arg-opt

Conversation

@arnaud-lb

@arnaud-lb arnaud-lb commented Jul 20, 2026

Copy link
Copy Markdown
Member

The branch includes GH-22785, but only the commit "PFA: Optimize constant pre-bound arguments" is relevant for this PR. (Edit: branch was rebased and doesn't include GH-22785 anymore.)


Currently PFA pre-bound arguments are bound to the generated closure's lexical vars:

function f($a, $b) {}
$f = f(1, ?);

// Generates:
$tmp = 1;
$f = function ($b) use ($tmp) {
    return f($tmp, $b);
};

In this PR we detect which pre-bound arguments are constant and burn them into the generated closure instead:

function f($a, $b) {}
$f = f(1, ?);

// Generates:
$f = function ($b) {
    return f(1, $b);
};

This reduces the overhead during both instantiation and invocation of PFAs.

Comment thread Zend/Optimizer/dfa_pass.c Outdated
Comment thread Zend/tests/partial_application/const_arg_opt.phpt

@iliaal iliaal left a comment

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.

Looks good!

Pre-bound arguments are bound to the generated closure's lexical vars:

```
function f($a, $b) {}
$f = f(1, ?);

// Generates:
$tmp = 1;
$f = function ($b) use ($tmp) {
    return f($tmp, $b);
};
```

Detect which pre-bound arguments are constant and burn them into the generated
closure instead:

```
function f($a, $b) {}
$f = f(1, ?);

// Generates:
$f = function ($b) {
    return f(1, $b);
};
```
@arnaud-lb
arnaud-lb force-pushed the partials-const-arg-opt branch from 5b670e7 to 62324a8 Compare July 27, 2026 16:00
@arnaud-lb
arnaud-lb merged commit edc169e into php:master Jul 27, 2026
18 checks passed
Comment thread Zend/zend_ast.c
Comment thread Zend/Optimizer/dfa_pass.c
Comment thread Zend/tests/partial_application/const_arg_opt.phpt
Comment thread Zend/tests/partial_application/const_arg_opt.phpt
arnaud-lb added a commit that referenced this pull request Jul 28, 2026
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