Closed (works as designed)
Project:
FileField
Version:
6.x-3.7
Component:
Code
Priority:
Minor
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
25 Aug 2010 at 00:00 UTC
Updated:
27 Apr 2011 at 04:47 UTC
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);
}
| Comment | File | Size | Author |
|---|---|---|---|
| drupal_load.PNG | 22.03 KB | andrewsuth |
Comments
Comment #1
andrewsuth commentedCorrected title to
require_onceand notinclude_onceComment #2
quicksketchCould 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.
Comment #3
quicksketch