If you look at the way http://api.drupal.org/api/function/drupal_get_schema_versions/7 is put together, it has caching which is only guaranteed to work correctly when the function is called for an installed module.

Currently, however, update_get_update_list() calls it for ALL modules on the site, including UNINSTALLED ones.

Uninstalled modules don't have their code loaded, so drupal_get_schema_versions() never finds anything for them. Therefore, each new call to that function results in a cache miss, and get_defined_functions() being called over and over again. This is slow.

The attached patch simply avoids that by having the update system not bother calling drupal_get_schema_versions() for uninstalled modules - there is absolutely no reason to. On my laptop, this saves somewhere between 0.25-0.5 seconds when running updates via Drush. This adds up, especially if you are updating lots of sites - which some people, like the company I work for, occasionally try to do :)

There are actually further improvements that one could imagine - for example, the update system is required to call this function for disabled (but not uninstalled modules), but if the disabled module doesn't happen to define any update functions at all, it will also result in a cache miss. However, this should be a less common situation compared to uninstalled modules (especially with all the uninstalled, hidden, testing-related modules that ship with D7), and to fix it we'd need to fix the cache of drupal_get_schema_versions() itself. Which I thought about doing until I read through the history at #521838: Clean up drupal_get_schema_versions(), and it scared me away :)

This patch should be a perfectly reasonable improvement on its own, so I figured I'd just stop now.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Status: Needs review » Reviewed & tested by the community

Nice one :)

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)
Issue tags: -Performance

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