|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-03-03 11:27 UTC] bugreports at gmail dot com
[2020-03-03 11:37 UTC] nikic@php.net
-Summary: optimize FETCH_CONSTANT
+Summary: Perform CSE of FETCH_CONSTANT
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 19 02:00:01 2025 UTC |
Description: ------------ i would have expected that opcache optimizes the repeated FETCH_CONSTANT out --------------------------------- define('IS_ROBOT', 1); function a() { return IS_ROBOT . IS_ROBOT . IS_ROBOT . IS_ROBOT; } function b() { $IS_ROBOT = IS_ROBOT; return $IS_ROBOT . $IS_ROBOT . $IS_ROBOT . $IS_ROBOT; } --------------------------------- ************************************************************************************************************* * VLD OPCACHE * ************************************************************************************************************* function name: a number of ops: 8 ------------------------------------------------------------------------------------- 7 0* FETCH_CONSTANT ~1 'IS_ROBOT' 1* FETCH_CONSTANT ~2 'IS_ROBOT' 2* FAST_CONCAT ~0 ~1, ~2 3* FETCH_CONSTANT ~2 'IS_ROBOT' 4* FAST_CONCAT ~1 ~0, ~2 5* FETCH_CONSTANT ~2 'IS_ROBOT' 6* FAST_CONCAT ~0 ~1, ~2 7* RETURN ~0 function name: b number of ops: 5 ------------------------------------------------------------------------------------- 12 0* FETCH_CONSTANT !0 'IS_ROBOT' 13 1* FAST_CONCAT ~1 !0, !0 2* FAST_CONCAT ~2 ~1, !0 3* FAST_CONCAT ~1 ~2, !0 4* RETURN ~1 Expected result: ---------------- i would have expexted that repeatet FETCH_CONSTANT within a function is optimized out like the second implementation doing it in userland by copy it to a local variable not that much of a performance overhead but on the other hand if it's a function which a loop using dozens of constants more than once.....