Req #76178 [NEW]: Class constants are slow: they should be inlined at runtime

From: Date: Mon, 02 Apr 2018 19:35:11 +0000
Subject: Req #76178 [NEW]: Class constants are slow: they should be inlined at runtime
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214568@lists.php.net to get a copy of this message
From: nicolas dot grekas+php at gmail dot com Operating system: PHP version: 7.2.4 Package: Scripting Engine problem Bug Type: Feature/Change Request Bug description:Class constants are slow: they should be inlined at runtime Description: ------------ On both Twig and Symfony, we noticed that in some performance-critical code paths, the most significant change we could do to improve performance was replacing class constants by their values. See: - https://github.com/twigphp/Twig/pull/2636/files - https://github.com/symfony/symfony/pull/26161/files While I understand that the reason for this is that opcode arrays are per-file, this could be optimized at runtime, by repalcing the const-fetch by its value on first access (similarly to what is done for non-namespaced functions.) Test script: --------------- function foo($a = SomeClassInAnotherFile::FOO) { } function bar($a = 123) { } Expected result: ---------------- Calling foo() and bar() without any arguments should be as fast for both functions. Actual result: -------------- Calling foo() is measurably slower than calling bar() -- Edit bug report at https://bugs.php.net/bug.php?id=76178&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76178&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76178&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76178&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=76178&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=76178&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=76178&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=76178&r=needscript Try newer version: https://bugs.php.net/fix.php?id=76178&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=76178&r=support Expected behavior: https://bugs.php.net/fix.php?id=76178&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=76178&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=76178&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=76178&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76178&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=76178&r=dst IIS Stability: https://bugs.php.net/fix.php?id=76178&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=76178&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=76178&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=76178&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=76178&r=mysqlcfg

« previous php.bugs (#214568) next »