78341[TASK] Improve performance of GeneralUtility::makeInstance()
Commit message
Review
-
Code review CR 0
-
Verified V 0
Issues 2
Files 1
Review log 1314
-
Christian Eßl uploaded patch set 1 03/31/23, 17:50
-
core-ci voted on patch set 1 V +1 03/31/23, 17:57 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/39912
-
Oliver Klee voted on patch set 1 CR +1 03/31/23, 18:54
-
Oliver Klee voted on patch set 1 V +1 03/31/23, 18:54
-
Markus Klein commented on patch set 1 V +1 CR +1 03/31/23, 19:01
Fine with me, but I won't argue about performance here, because I have no numbers -
Benni Mack commented on patch set 1 03/31/23, 19:59
I'm fine also backporting this to 11.5 -
Christian Eßl commented on patch set 1 03/31/23, 20:23
Reply
str_starts_with() was only introduced in this line with #100091, which is exclusively v12. Before, it was already $className[0] === '\\'. So no need to backport it to 11.5.Reply
In isolated tests with PHP 8.1 around 20 times faster than using str_starts_with. -
Markus Klein commented on patch set 1 03/31/23, 22:01
Reply
Alright.. that's a number -
Simon Schaufelberger voted on patch set 1 V +1 CR +1 04/01/23, 02:49
-
Christian Kuhn commented on patch set 1 V -1 CR -1 04/01/23, 02:53
Hey. I hope we agree we're talking about artificial micro optimizations here. I was curious and couldn't believe neither your "MUCH faster", nor your "20 times faster" claim. Test script, comparing 100.000 random strings for first char: https://3v4l.org/07iHL#v8.1.17 3v4l.org says: no difference, both are same speed. local execution says: no difference with php 8.2.3 (no xdebug), with php 8.1.16 (no xdebug) it's array-access 1ms, str_starts_with 2.7ms. No idea why my local 8.1 is shows a difference, maybe due to different set of loaded php extensions. Taking this worst case, ignoring that I did not see *any* difference with other versions, it's about 1.5 times slower than the array access. Not 100 times. 1.5ms for 100k calls means: about 15 nanosecond per call. Assuming we'll create maybe 1k objects realistically (that's much), that's 15 microseconds in real life. That's 1.5 * 10^-6 seconds. -> Not worth it. Let's not sacrifice readability for something that has only tiny improvement in some versions when measured artificially and has no real life impact anyways. -
Christian Eßl commented on patch set 1 04/01/23, 05:46
Reply
Hey, just checked it in PHP 8.2 and I still see the same differences between the two methods. But it really depends on the setup. When I turn on blackfire or xdebug, the performance differences become so small, they don't matter anymore at all. But as soon as I turn those tools off, in my tests with a large request with ~1000 instanciated objects with GeneralUtility::makeInstance() (in this case ajax/filestorage/tree/fetchData), this usually saved 200-300ms. Maybe I can create an automated test later, that provides some good averages... -
Oliver Klee commented on patch set 1 V 0 CR 0 04/01/23, 07:56
Now that I think about it, I'd prefer to have readability of performance unless we have a real bottleneck. -
Christian Eßl commented on patch set 1 V -1 CR -1 04/01/23, 08:02
Reply
Hm, now after restarting ddev, the performance differences disappear completely. Not sure, what is different between my php setups, but it is probably really not worth it, so I'll abandon this change. -
Christian Eßl abandoned the change 04/01/23, 08:02