Skip to content

perf(optimizer): lower simple integer min/max calls - #96

Merged
matyhtf merged 2 commits into
swoole:masterfrom
yavon007:codex/optimize-integer-min-max
Sep 8, 2026
Merged

perf(optimizer): lower simple integer min/max calls#96
matyhtf merged 2 commits into
swoole:masterfrom
yavon007:codex/optimize-integer-min-max

Conversation

@yavon007

@yavon007 yavon007 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Two-argument min()/max() calls currently cross the Zend call boundary even when their operands are exact integers. This optimization lowers eligible calls to scalar comparisons, avoiding argument boxing and runtime dispatch.

The fast path accepts native integer variables, integer literals/casts, and resolved non-nullable integer instance properties. Other forms retain the existing runtime path. Casts are evaluated once, and ordinary variable evaluation behavior is preserved.

The included O2 benchmark improves from 482.56 ms to 48.01 ms (10.05x) for 10 million iterations: nine measured pairs, PHP 8.5.10 ZTS, Linux ARM64, PHPX 6a68f38. Reproduction instructions and raw samples are included in benchmark/min-max.

Validation:

  • Focused PHPUnit: 3 tests, 30 assertions passed.
  • Related PHPTs: 38 passed, covering nullable values, varint overflow, cast evaluation counts, side effects, short-circuiting and namespace resolution.
  • Broad PHPUnit: 1,963 tests; three existing PythonModuleTest generated-code assertion failures also reproduce with the unmodified baseline optimizer.
  • Independent review and git diff --check passed.

@matyhtf
matyhtf merged commit 692841a into swoole:master Sep 8, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants