Req #79337 [Com]: optimize FETCH_CONSTANT

From: Date: Tue, 03 Mar 2020 11:27:37 +0000
Subject: Req #79337 [Com]: optimize FETCH_CONSTANT
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225864@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79337&edit=1 ID: 79337 Comment by: bugreports at gmail dot com Reported by: bugreports at gmail dot com Summary: optimize FETCH_CONSTANT Status: Open Type: Feature/Change Request Package: opcache PHP Version: 7.4Git-2020-03-03 (Git) Block user comment: N Private report: N New Comment: 50 Mio calls without and with opcache, a full second runtime difference while native optimization could be faster than the handcrafted copy into a local variable is a lot of runtime given it's just 4 usages in real world code this could sum up much more when it's a funtion lopping over some large array and using the same constant thousands of times at once a(): 11.7516 b(): 10.9853 a(): 10.9835 b(): 9.9896 Previous Comments: ------------------------------------------------------------------------ [2020-03-03 11:16:58] bugreports at gmail dot com 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..... ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79337&edit=1

« previous php.bugs (#225864) next »