opcache: re-enable PASS_15 (constant collection) by default#22007
opcache: re-enable PASS_15 (constant collection) by default#22007wilaak wants to merge 2 commits into
Conversation
e57f1f4 to
c5e2cf5
Compare
Disabled in Dec 2015 (940c68b, 4070279) to fix bug #71127. define() and attributed constants are blocked from inlining via a sentinel entry. define() can be overridden at runtime (bug #71127) and attributed constants need to fire at access time. The sentinel also prevents inlining of any subsequent const redeclaration of the same name. Adds zend_optimizer_block_constant() for sentinel logic.
c5e2cf5 to
35cd64d
Compare
| --FILE-- | ||
| <?php | ||
|
|
||
| const CONST_VAL = 1; |
There was a problem hiding this comment.
please also add tests for what happens if the constant is already declared in a separate file
There was a problem hiding this comment.
If the constant is only declared in the separate file the optimizer can't inline it since the value is unknown at compile time, so it emits FETCH_CONSTANT.
If you also redeclare it locally the optimizer inlines the local value, but at runtime the required declaration wins and the local one warns. You get different results with and without opcache, so there's a real divergence there!
|
We can't enable this optimization by default because of the "stupid" PHP redeclaration behavior. In general, constant may de defined in different files, and we can't use declaration from the current file, because it might be declared early. |
|
That's stupid but I see now. Top level constants are all runtime unlike class constants. Hopefully some of that behaviour could change in the future. |
PASS_15 was disabled in Dec 2015 (940c68b, 4070279) to fix bug #71127.
define() values are not inlined; a sentinel entry also blocks inlining of any subsequent const redeclaration of the same name. Attributed constants are similarly blocked since their attributes need to fire at access time.
Not 100% sure every edge case is covered or if this is a good approach.
Dmitry, does this look safe to you?
Probably not worth it for the tiny benefit it provides. It only provides perf gains if you were to define and use it in the same file. Should I close this as it's a better idea to defer until the optimizer can do whole-program analysis?