This wouldn't really help with the case here of "if ($array1 == $array2)..." though right? (not to say it's not good, just making sure I understand ;-) ).

Yes I'm talking about speeding up scenarios full of hash lookups in general.


It sounds like this would only work if the array contents where static though, as you're mapping a constant string to the contents of the hash (or did I misunderstand and you'd be mapping string const. values to hash IDs?).

My point is, replacing this process:

$a['foo'] or $a->foo -> compute hash of 'foo' -> find item for hash 'foo' -> many items? -> resolve conflict -> return item

With this process:

$a[% string_literal_id_5 %] -> lookup item key 5 for array -> return item

Notice we skipped hash generation, and conflict resolution altogether. We only have the lookup for the integer id. If some additional work is done, even this lookup can be eliminated and make this an O(1) process.

If instead the coder used variable:

$a[$bar] or $a->$foo (var array lookup and var var object lookup), then this optimization can't kick in, and the existing algorithm will be used.

However "static" access is the predominant usage, especially for objects, but also for arrays, so this should have significant impact.

Regards, Stan Vassilev

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to