|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81090 Typed property performance degradation with .= operator
Submitted: 2021-05-30 12:41 UTC Modified: 2021-05-31 10:17 UTC
Avg. Score:4.8 ± 0.6
Reproduced:11 of 11 (100.0%)
Same Version:11 (100.0%)
Same OS:11 (100.0%)
From: dktapps at pmmp dot io Assigned:
Status: Closed Package: Performance problem
PHP Version: 7.4.19 OS: Windows
Private report: No CVE-ID: None
 [2021-05-30 12:41 UTC] dktapps at pmmp dot io
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:

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-05-30 13:28 UTC] 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):
Without type (<1s, 1,000,000 loops):
 [2021-05-31 10:17 UTC]
-Status: Open +Status: Analyzed
 [2021-05-31 10:17 UTC]
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-31 10:34 UTC]
Automatic comment on behalf of nikic
Log: Fixed bug #81090
 [2021-05-31 10:34 UTC]
-Status: Analyzed +Status: Closed
 [2021-05-31 10:40 UTC]
Automatic comment on behalf of nikic
Log: Fix bug #81090 in JIT as well
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jun 21 08:01:34 2024 UTC