Req #76178 [Opn]: Class constants are slow: they should be inlined at runtime
| From: | nicolas dot grekas+php at gmail dot com | Date: | Mon, 02 Apr 2018 19:36:40 +0000 |
| Subject: | Req #76178 [Opn]: Class constants are slow: they should be inlined at runtime | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-214569@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76178&edit=1
ID: 76178
User updated by: nicolas dot grekas+php at gmail dot com
Reported by: nicolas dot grekas+php at gmail dot com
Summary: Class constants are slow: they should be inlined at
runtime
Status: Open
Type: Feature/Change Request
Package: Scripting Engine problem
PHP Version: 7.2.4
Block user comment: N
Private report: N
New Comment:
Oups, bad link for Symfony, here is the correct one:
https://github.com/symfony/symfony/pull/25474/files
Previous Comments:
------------------------------------------------------------------------
[2018-04-02 19:35:09] nicolas dot grekas+php at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=76178&edit=1