Bug #81090 [Ana->Csd]: Typed property performance degradation with .= operator
| From: | git@php.net | Date: | Mon, 31 May 2021 10:34:46 +0000 |
| Subject: | Bug #81090 [Ana->Csd]: Typed property performance degradation with .= operator | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-234103@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81090&edit=1
ID: 81090
Updated by: git@php.net
Reported by: dktapps at pmmp dot io
Summary: Typed property performance degradation with .=
operator
-Status: Analyzed
+Status: Closed
Type: Bug
Package: Performance problem
Operating System: Windows
PHP Version: 7.4.19
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikic
Revision: https://github.com/php/php-src/commit/82f6f6da67a265170fe533d97edb59520da0024f
Log: Fixed bug #81090
Previous Comments:
------------------------------------------------------------------------
[2021-05-31 10:17:11] nikic@php.net
This happens because typed properties perform binary operations into a temporary first, so that the
original value is retained if a TypeError occurs.
------------------------------------------------------------------------
[2021-05-30 13:28:20] dktapps at pmmp dot io
Profiling shows that the vast majority of the CPU time is spent in concat_function(), but only for
the typed property.
This bug also persists on PHP 8.0 with function JIT enabled.
The performance degradation is exponential with higher loop count, which leads me to believe that
every .= on a typed property is triggering a full string copy for some reason, despite the
string's refcount being 1.
With type (7m 30s, 1,000,000 loops): https://user-images.githubusercontent.com/14214667/120105960-05484200-c153-11eb-8540-00e8ea39e0a7.png
Without type (<1s, 1,000,000 loops): https://user-images.githubusercontent.com/14214667/120105988-29a41e80-c153-11eb-8337-ed91a41fe1fc.png
------------------------------------------------------------------------
[2021-05-30 12:41:01] dktapps at pmmp dot io
Description:
------------
There appears to be a change in the behaviour of .= with typed properties, as compared to typeless
properties.
The below script demonstrates a significant performance degradation with typed properties (in the
ballpark of 2 orders of magnitude).
Test script:
---------------
https://gist.github.com/dktapps/8a5d839f4c884f92d0b56f04c3b7d7d4
Expected result:
----------------
The time per operation should only be slightly slower for typed properties than typeless properties
(like it is for other things, like plain assignments).
Actual result:
--------------
The time per operation is 2 orders of magnitude worse on the first loop than the second one.
On my machine, the script produces the following:
Typed property time: 8701.32 ns/op
Typeless property time: 211.446 ns/op
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81090&edit=1