Req #76178 [Opn->Csd]: Class constants are slow: they should be inlined at runtime
| From: | dmitry@php.net | Date: | Thu, 03 May 2018 11:45:54 +0000 |
| Subject: | Req #76178 [Opn->Csd]: Class constants are slow: they should be inlined at runtime | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-215033@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
Updated by: dmitry@php.net
Reported by: nicolas dot grekas+php at gmail dot com
Summary: Class constants are slow: they should be inlined at
runtime
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Scripting Engine problem
PHP Version: 7.2.4
-Assigned To:
+Assigned To: dmitry
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2018-05-03 11:45:42] dmitry@php.net
Implemented in master.
https://github.com/php/php-src/commit/1a63fa6ec9b0bacbb726e60c3c212e7d97b518c6
------------------------------------------------------------------------
[2018-04-05 16:46:17] nicolas dot grekas+php at gmail dot com
@kelunik sure, but that's not true anymore when taking inheritance into account (and the parent
class is in another file.)
------------------------------------------------------------------------
[2018-04-05 16:43:13] kelunik@php.net
Class constants should already be inlined in case they're from the same class they're used
in: https://3v4l.org/jM5BA/vld#output
------------------------------------------------------------------------
[2018-04-02 19:36:39] nicolas dot grekas+php at gmail dot com
Oups, bad link for Symfony, here is the correct one:
https://github.com/symfony/symfony/pull/25474/files
------------------------------------------------------------------------
[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