Currently, admin_menu_element_sort() calls is_array() on the passed menu items to ensure they are arrays before fetching the weight, and, if the weights are equal, it calls is_array() on the elements again prior to attempting to fetch the title for comparison.
The attached patch pre-checks if the passed elements are arrays, then uses that value in place of the subsequent calls to is_array().
On the website I am currently developing, this saves 40,662 calls to is_array(), and saves 152ms over 22,425 invocations on admin_menu_element_sort().
Patch attached, along with the diff between two xhprof runs.
Comment | File | Size | Author |
---|---|---|---|
#2 | admin_menu.element-sort.2.patch | 966 bytes | sun |
Screenshot at 2012-07-20 12:22:10.png | 148 KB | brianV | |
improve_admin_menu_element_sort.patch | 1.07 KB | brianV | |
Comments
Comment #1
brianV CreditAttribution: brianV commentedForgot to mark as 'Needs Review'
Comment #2
sunActually, I wonder whether we need to check for is_array() at all?
Will it fatal in the edge-case of bogus data? Notices/warnings, sure... but fatal, I can't see why?
Comment #3
brianV CreditAttribution: brianV commentedI had the same thoughts, but figured better to be safe than sorry.
I did run a profile with that, although I didn't screenshot it. Removing the is_array() altogether nets a further 90ms or so savings on my machine.
Comment #4
sunThanks for reporting, reviewing, and testing! Committed to all branches.
A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.