Task #56025
closed
Replace array_key_exists() with (isset($array[$key]) || array_key_exists())
Added by Michiel Roos almost 11 years ago.
Updated over 5 years ago.
Description
Calling array_key_exists can be avoided most of the time by using isset().
isset() may however return FALSE for cases where there is in fact an existing key, but where the value is NULL. So we need to OR the isset() with the old array_key_exists to have a fallback in place for the cases where the array value is a NULL.
- Status changed from New to Under Review
Did you ever try to take a look at the Backend Log module?
This is the reason I went down this path. There are around a million method calls going on in there. About 931.908 on a good day. All to render 500 records of log with links to a history detail page if appropriate.
After applying this patch (and using a language construct over a more expensive PHP function), for the Backend Log, a reduction by 19.041 method calls is measured. That's 2%.
Memory usage is reduced by about 17% for the Backend Log request.
- Status changed from Under Review to Accepted
- Target version deleted (
6.2.0)
- Complexity changed from no-brainer to medium
The current patch incarnation has been abandoned.
The solution must be to use isset() exclusively and array_key_exists() only if required. Needs a case-by-case inspection.
- Category set to Performance
- Status changed from Accepted to Closed
As there hasn't been any work done on this issue for 4 years, I'm closing this issue now. If anyone wants to pick it up again, please validate the performance improvements with newer PHP versions and vs. null coalescing - and open a new issue :)
Also available in: Atom
PDF