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.

#2 admin_menu.element-sort.2.patch966 bytessun
PASSED: [[SimpleTest]]: [MySQL] 228 pass(es). View
Screenshot at 2012-07-20 12:22:10.png148 KBbrianV
improve_admin_menu_element_sort.patch1.07 KBbrianV
PASSED: [[SimpleTest]]: [MySQL] 228 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more


brianV’s picture

Status: Active » Needs review

Forgot to mark as 'Needs Review'

sun’s picture

966 bytes
PASSED: [[SimpleTest]]: [MySQL] 228 pass(es). View

Actually, 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?

brianV’s picture

I 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.

sun’s picture

Status: Needs review » Fixed

Thanks 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.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.