After analysing a sites modules using webgrind, I noticed 2 modules stood out from the others regarding the time they spent in drupal_load: filefield and imagefield. (see diagram attached)

It seems these modules both perform include_once calls in the main code, which bloats the drupal_load times.

An optimised solution would be to create a seperate function to load the include files and use a static cache to verify if it has already been loaded. An example of this can be seen in the Views module:

/**
 * Include views .inc files as necessary.
 */
function views_include($file) {
  static $used = array();
  if (!isset($used[$file])) {
    require_once './' . drupal_get_path('module', 'views') . "/includes/$file.inc";
  }

  $used[$file] = TRUE;
}

Then when a function from an include file is needed:

/**
 * Fetch Views' data from the cache
 */
function views_fetch_data($table = NULL) {
  views_include('cache');
  return _views_fetch_data($table);
}
CommentFileSizeAuthor
drupal_load.PNG22.03 KBandrewsuth

Comments

andrewsuth’s picture

Title: Move include_once function calls to own static caching function to lighten drupal_load times » Move require_once function calls to own static caching function to lighten drupal_load times

Corrected title to require_once and not include_once

quicksketch’s picture

Priority: Normal » Minor

Could you provide a patch with your suggested changes? I'm not sure we can really move those .inc files to inside of functions (other than maybe hook_init()), since they actually contain hooks and functions that need to be available at all times.

quicksketch’s picture

Status: Active » Closed (works as designed)