t() calles module_exist("locale") every time it is invoked, replacing this call by function_exists doubles the speed of t().

CommentFileSizeAuthor
20040109.locale-module-exist.patch628 bytesbart jansens

Comments

gábor hojtsy’s picture

If we really want to get rid of t() speed problems, then we can cache the return value of the check done on every t() call, since $languages and module_exists('locale') is not supposed to change in a Drupal run AFAIK. Something like:

static $translate = NULL;

if (!isset($translate)) {
  $translate = ($languages && module_exist("locale"));
}
else {
  $string = ($translate ? t($string) : $string);
}

...

That would only cost an isset() check second and all subsequent times t() is called. This is probably just nitpicking though... I am not sure this would lead to any significant gains... Maybe.

gábor hojtsy’s picture

The recursive call to t() is just a typo, I mean locale() :)

killes@www.drop.org’s picture

I propose to change the implementation of module_exist instead.
Currently it uses isset($list[$name]) which seems fo be slower than function_exists(). We should do a function_exists on a function that every module has. (_help?).

moshe weitzman’s picture

does anyone have any benchmarks to justify the claim of 2x speed increase with this patch?

Anonymous’s picture

Actually i should stay away from my computer when i have a headache, makes me remember things all wrong. The 2x was just in a special case, otherwise the difference isnt that big (5ms vs 6ms iirc).

moshe weitzman’s picture