Skip to content

Keep boolean condition snapshots in native storage - #106

Open
yavon007 wants to merge 3 commits into
swoole:masterfrom
yavon007:codex/native-condition-temporaries
Open

Keep boolean condition snapshots in native storage#106
yavon007 wants to merge 3 commits into
swoole:masterfrom
yavon007:codex/native-condition-temporaries

Conversation

@yavon007

@yavon007 yavon007 commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Conditions with operand cleanup must save their result before releasing the
operands. Both branch conditions and short-circuit right operands currently
box that saved result in php::Var, even when its type is known to be boolean.

Use php::Bool only for inferred boolean snapshots, normalizing the emitted
value through php::toBool before the existing cleanup. Keep other result
types boxed. Evaluation order, short-circuit behavior, and operand cleanup
remain intact. Add code-generation coverage for the optimized boolean cases
and a mixed-return call that must retain the Variant fallback.

Static initializer lambdas start their temporary counter after captured outer
locals, preventing initializer array temporaries from accidentally reusing an
outer boolean snapshot. A PHPT covers nested static arrays after a condition.
The complete 135-file compiler self-build, its --version invocation, and
compiling/running the regression with the resulting compiler all pass locally.

Validation: focused codegen/evaluation-order tests pass; separately compiled
existing short-circuit, condition-side-effect, and weak-reference lifetime
cases match expected stdout with empty stderr. The 51-assertion dungeon suite
matches PHP. Independent review found no remaining issue.

On Linux ARM64, GCC O2, PHP 8.5.10 ZTS and PHPX 4b3a472, two final-source
alternating baseline/candidate measurement batches reduce normal-only elapsed
time by 5.18% and 4.73% (100,000 games/sample), and exception-heavy elapsed
time by 6.26% and 3.75% (20,000 games/sample). Each batch uses one warmup pair
and five measured pairs; output is checked every time. The game sources are
unchanged. The command function replaces six Variant temporaries with Bool.

This PR is based directly on master and does not include or require #105.
The reported performance experiment included #105 (10629f60) in both binaries;
neither binary included #104. These percentages have not been remeasured
without #105.
Results are workload/platform-specific. Other platforms and Python
interoperability have not been runtime-tested for this change.

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.

1 participant