Bug #67124 [Asn->Csd]: Typecast (bool) $array slowdown according to array length

From: Date: Wed, 27 Aug 2014 10:01:28 +0000
Subject: Bug #67124 [Asn->Csd]: Typecast (bool) $array slowdown according to array length
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187293@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67124&edit=1 ID: 67124 Updated by: nikic@php.net Reported by: vovan-ve at yandex dot ru Summary: Typecast (bool) $array slowdown according to array length -Status: Assigned +Status: Closed Type: Bug Package: Performance problem Operating System: Linux PHP Version: Irrelevant Assigned To: dmitry Block user comment: N Private report: N New Comment: Fixed in PHP 7. Previous Comments: ------------------------------------------------------------------------ [2014-05-05 18:05:29] fastest963 at gmail dot com Instead of (bool) count($array), you can use empty($array), which seems cleaner and more obvious. Using empty() results in: $empty 0.10 sec. total $full 0.10 sec. total ------------------------------------------------------------------------ [2014-04-29 10:10:37] johannes@php.net Yes, the guess is correct - we copy the array, then "convert" the copy see ZEND_CAST opcode handler http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_operators.c#511 I don't see an obvious way to improve this without duplicating the conversion logic. You have an idea Dmitry? ------------------------------------------------------------------------ [2014-04-27 07:19:04] hanskrentel at yahoo dot de Workaround to get the timings low in the test-script only. And I didn't meant that in a positive fashion. A workaround is always crap and expensive. However, as internally it might be easy to get the array value count, the internal function that so far converts array into boolean could be optimized by looking for such array count instead of iterating through it. And yes I did expect something else. I was quite astonished how expensive the bool cast is with arrays with more than 100 members. I didn't know that so far. I always expected casts to be quick, I hope this gets fixed. ------------------------------------------------------------------------ [2014-04-26 12:59:57] vovan-ve at yandex dot ru Yes, "workaround" to pass thru the bugs maze. Welcome to PHP. Did you expect something else?.. ------------------------------------------------------------------------ [2014-04-26 09:43:59] hanskrentel at yahoo dot de The workaround is to first count with arrays as the count is cached. (bool) count($array); ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=67124 -- Edit this bug report at https://bugs.php.net/bug.php?id=67124&edit=1

« previous php.bugs (#187293) next »