I just noticed that hook_init implementation consumes lots of time. for me around 100-200ms. After tracing the code i noticed that _syntaxhighlighter_get_lib_location does recursive scan on every page.
I suggest using a variable to cache the result or using drupal caching system.

Comments

sinasalek’s picture

I used this modfied version to test the difference.

function _syntaxhighlighter_get_lib_location() {
  $result=variable_get('syntaxhighlighter_lib_location',null);
  if (!$result) {
      $directories = array(
        drupal_get_path('module', 'syntaxhighlighter'),
        file_directory_path(),
        'sites/all/libraries',
      );
      foreach ($directories as $d) {
        foreach (file_scan_directory($d, 'shCore\.js$', array('.', '..', 'CVS', 'src')) as $filename => $file_info) {
          $result=substr($filename, 0, -18);    // the path to syntaxhighlighter lib, (-18 to chop off "/scripts/shCore.js" at the end
          variable_set('syntaxhighlighter_lib_location',$result);
          return $result;
        }
      }
      return NULL;
  } else {
    return $result;
  }
}
sinasalek’s picture

There is two solutions :
- Using caching functions like cache_get,cache_set to cache the location
- Using variable and update it whenever user visits syntaxhighlighter admin page
- Both!

mattyoung’s picture

Status: Active » Needs review

I implemented lib location caching in variable. Drupal caches variable so storing the location value in variable should be good enough. Try the 'dev' version when the release bot make a new 'dev' release later today, or do cvs checkout of 'HEAD'

Thanks!

sinasalek’s picture

Cool.
The reason for cache solution was to let users update the path simply by clearing the cache like many other modules

mattyoung’s picture

> let users update the path simply by clearing the cache like many other modules

I forgot to mention here: visit the module setting page will cause a re-scan of lib location.

Let me know if this is okay enough.

sinasalek’s picture

That's fine for me. Thanks

mattyoung’s picture

Version: 6.x-1.9 » 6.x-1.22
Status: Needs review » Fixed

~

Status: Fixed » Closed (fixed)

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