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

From: Date: Thu, 05 Apr 2018 16:43:13 +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-214624@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: kelunik@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 Type: Feature/Change Request Package: Scripting Engine problem PHP Version: 7.2.4 Block user comment: N Private report: N New Comment: Class constants should already be inlined in case they're from the same class they're used in: https://3v4l.org/jM5BA/vld#output Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#214624) next »