Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61165 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95301 invoked from network); 12 Jul 2012 13:33:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jul 2012 13:33:31 -0000 Authentication-Results: pb1.pair.com header.from=jille@quis.cx; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=jille@quis.cx; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain quis.cx from 82.94.237.14 cause and error) X-PHP-List-Original-Sender: jille@quis.cx X-Host-Fingerprint: 82.94.237.14 mulgore.hexon-is.nl Received: from [82.94.237.14] ([82.94.237.14:49174] helo=mulgore.hexon-is.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 99/39-46517-922DEFF4 for ; Thu, 12 Jul 2012 09:33:30 -0400 Received: from adidas.hexon-nijmegen.nl (gw.hexon-nijmegen.nl [82.93.241.107]) by mulgore.hexon-is.nl (8.14.3/8.14.3) with ESMTP id q6CDXMRq012247; Thu, 12 Jul 2012 15:33:22 +0200 Received: from [10.0.0.137] (pcjille.hexon-nijmegen.nl [10.0.0.137]) by adidas.hexon-nijmegen.nl (8.14.3/8.14.3) with ESMTP id q6CDXMVF022045; Thu, 12 Jul 2012 15:33:22 +0200 Message-ID: <4FFED222.3040102@quis.cx> Date: Thu, 12 Jul 2012 15:33:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: =?UTF-8?B?Sm9oYW5uZXMgU2NobMO8dGVy?= CC: internals@lists.php.net References: <4FFEB86D.3080302@quis.cx> <1342099134.1440.9.camel@guybrush> In-Reply-To: <1342099134.1440.9.camel@guybrush> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Hexon-MailScanner-Information: Please contact the ISP for more information X-Hexon-MailScanner-ID: q6CDXMRq012247 X-Hexon-MailScanner: Found to be clean X-Hexon-MailScanner-From: jille@quis.cx X-Hexon-MailScanner-Watermark: 1342704803.49544@2UOeUBIOXkekC1ftd9yJPA Subject: Re: [PHP-DEV] array_shift() and reindexing From: jille@quis.cx (Jille Timmermans) Op 12-07-12 15:18, Johannes Schlüter schreef: > On Thu, 2012-07-12 at 13:43 +0200, Jille Timmermans wrote: >> Hello, >> >> array_shift() currently reindexes the array after shifting one element. >> The reindexing has quite some impact on it's performance. I would like >> to suggest an extra parameter to array_shift() which can be used to >> prevent reindexing. >> >> From a few quick (and sloppy!) tests I get these results: >> `reset($array); list($key, $value) = each($array); >> unset($array[$key]);` is ~50-150 times faster than array_shift(). >> Calling array_reverse() and using array_pop() is ~2000-5000 times faster. >> >> If you agree this would be an useful addition I will create a patch. > I haven't checked this, but is the difference only due to the re-hashing > or also due to the fact that that array_shift() is taking the array by > reference and therefore making a copy during the call if other > cow-references (refcount>1, isref=0) exist? If I disable the reindexing code array_shift() becomes ~300 times faster. -- Jille