Bug #81090 [Com]: Typed property performance degradation with .= operator

From: Date: Sun, 30 May 2021 13:28:20 +0000
Subject: Bug #81090 [Com]: Typed property performance degradation with .= operator
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234100@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 Comment by: dktapps at pmmp dot io Reported by: dktapps at pmmp dot io Summary: Typed property performance degradation with .= operator Status: Open Type: Bug Package: Performance problem Operating System: Windows PHP Version: 7.4.19 Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#234100) next »