Skip to content

Prevent inlining of zend_compile_expr_inner() to guarantee low stack usage of compilation - #23294

Open
kubawerlos wants to merge 2 commits into
php:masterfrom
6b7562617765726c6f73:prevent-inlining-of-zend_compile_expr_inner-to-reduce-stack-usage-of-compilation
Open

Prevent inlining of zend_compile_expr_inner() to guarantee low stack usage of compilation#23294
kubawerlos wants to merge 2 commits into
php:masterfrom
6b7562617765726c6f73:prevent-inlining-of-zend_compile_expr_inner-to-reduce-stack-usage-of-compilation

Conversation

@kubawerlos

@kubawerlos kubawerlos commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

zend_compile_expr_inner() sits in the per-nesting-level recursion cycle of the compiler but normally releases its ~456-byte frame via a tail call before recursing, so a nesting level costs ~155 bytes of stack. Inlined into the cycle, the cost triples (~467 bytes) and the max nesting depth under a 1 MB zend.max_allowed_stack_size drops from ~6700 to ~2200. This actually happened: 07d308a made GCC start inlining it (master shipped ~3 weeks with 3× cost until deeply nested generated code stopped compiling), and fde23df accidentally undid it. Both flips were side effects of unrelated lineno changes — which are planned to return in another form. zend_never_inline makes the cheap state guaranteed instead of accidental; on current master (GCC 13.3 -O2) the compiled output is byte-identical with and without it.

No regression test: one existed while the inlined state was on master and genuinely discriminated there, but since fde23df both builds are identical, so it passes either way on release builds while false-failing on debug (-O0) builds. A test cannot detect an annotation with no observable effect; the attribute and its code comment carry the protection.

@kubawerlos kubawerlos changed the title Prevent inlining of zend_compile_expr_inner() to reduce stack usage of compilation Prevent inlining of zend_compile_expr_inner() to guarantee low stack usage of compilation Aug 15, 2026
@kubawerlos
kubawerlos marked this pull request as ready for review August 15, 2026 14:21
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.

1 participant