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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

brianV’s picture

Status: Active » Needs review

Forgot to mark as 'Needs Review'

sun’s picture

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.