Edit report at https://bugs.php.net/bug.php?id=60836&edit=1

 ID:                 60836
 Comment by:         phristen at yahoo dot com
 Reported by:        oliver at hofff dot com
 Summary:            Improve array_intersect_key performance
 Status:             Open
 Type:               Feature/Change Request
 Package:            Arrays related
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

carloschilazo, what you said doesn't make sense.
Intersecting A, B, and C will produce the same result as intersecting C, B, and 
A, or any other combination of the operands.

Unfortunately, a lot of PHP array functions are known to be extremely 
inefficient :(


Previous Comments:
------------------------------------------------------------------------
[2012-01-27 03:52:11] carloschilazo at gmail dot com

we cant start walking the shortest array given, because we first need to know 
which elements we need to look in the other arrays, and those are the ones 
presesnt in the first array

" returns an array containing all the entries of array1 which have keys that 
are 
present in all the arguments. "

------------------------------------------------------------------------
[2012-01-22 00:34:49] oliver at hofff dot com

Description:
------------
The trivial test script below runs longer than the extpected "instant" 
execution (lot longer).

This is because the algorithm walks the first argument and looks up the key in 
every other array supplied as an argument.

Instead it should walk the shortest array given, and look up the keys in every 
other array.

Maybe this issue or similar ones also apply to other array functions, which 
perform set operations, but I have not checked the code of them.

Of course the optimization could be done in userland, but that feels not right.

Test script:
---------------
$arr = array_fill(0, 1000000, '...');
$i = 1000;
while($i--) {
array_intersect_key($arr, array());
}



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=60836&edit=1

Reply via email to