php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37563 array_key_exists performance is poor for &$array
Submitted: 2006-05-23 17:16 UTC Modified: 2006-05-25 22:39 UTC
From: bugs dot php dot net at nanonanonano dot net Assigned: ilia (profile)
Status: Closed Package: Performance problem
PHP Version: 5CVS-2006-05-23 (snap) OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bugs dot php dot net at nanonanonano dot net
New email:
PHP Version: OS:

 

 [2006-05-23 17:16 UTC] bugs dot php dot net at nanonanonano dot net
Description:
------------
If there is a reference taken to an array ($b =& $a) then the performance of array_key_exists($foo, $a) drops off enormously unless array_key_exists($foo, &$a) is used.

(Note this is identical to #30295 which is marked as fixed in CVS but doesn't appear to be fixed at all: it is found in both 4CVS and 5CVS)

Reproduce code:
---------------
Based on the code in bug #30295:

    http://pastebin.com/733286

Expected result:
----------------
Time for the following operations should be approximately the same:

array_key_exists($i, $a);

$b =& $a; array_key_exists($i, $a);

$b =& $a; array_key_exists($i, &$a);

Actual result:
--------------
Time for 

$b =& $a; array_key_exists($i, $a);

is significantly greater than for the others.

Sample times from running the reproduce code:

Test with no refs:                    0.0012528896331787
Test with a ref to the array:         0.78344106674194
Test with a ref to the array and pass by ref: 0.0019340515136719


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-24 20:07 UTC] tony2001@php.net
Ilia, could you plz have a look at it?
 [2006-05-24 23:14 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2006-05-25 10:15 UTC] bugs dot php dot net at nanonanonano dot net
Thanks for the prompt attention.

Just one last thing -- the fix only went into 5CVS and as noted in the original bug report the problem exists in 4CVS too. Any chance of backporting the fix?


# test with 4CVS (php4-STABLE-200605250830)
Test with no refs:                            0.0027539730072021
Test with a ref to the array:                 0.89111185073853
Test with a ref to the array and pass by ref: 0.0028078556060791

Thanks in advance!
 [2006-05-25 22:39 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

it cannot be back ported to PHP4 as the fix relies on PHP 5 
only code.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC