I spent some time trying to speed up the cache flush of a website. I discovered that menu_rebuild() calls the hook implementation xmlsitemap_menu_menu_link_alter() for every little menu link, performing many database operations through xmlsitemap_menu_xmlsitemap_process_menu_links().
Even when the frontend menus are empty, this takes much time because the management menu can still have many links.
Here's a way to improve it:
<?php
function xmlsitemap_menu_xmlsitemap_process_menu_links(array $mlids, array $xmlsitemap = array()) {
// Performance hack: exclude administrative menus from XML Site Map.
static $allowed_mlids;
if (variable_get('xmlsitemap_menu_exclude_admin_menus', FALSE)) {
if (!isset($allowed_mlids)) {
$result = db_query('SELECT mlid FROM {menu_links} WHERE menu_name NOT IN (:admin_menus)', array(':admin_menus'=> array('management', 'navigation', 'devel')));
$allowed_mlids = $result->fetchCol();
}
$mlids = array_intersect($mlids, $allowed_mlids);
}
// Set the global user variable to the anonymous user.
...
?>
What do you think?