The attached patch file (which should be placed in the parent directory above Advanced help module directory to be applied properly) should increase performance of each page request.
It stores the result of help file discovery (which runs via hook_init() for everey page request) in Drupal's core cache table.

So you have to click your "Empty cache" button (on performance settings admin page or in Devel navigation block) after adding new help files to start a new discovery cycle.

Maybe this patch is helpful for people that are interested in performance tweaking for huge Drupal installations.

Another idea could be integrating this patch in the next release and give the user a way to decide if cache should be used (e.g. by setting a variable in settings.php or via an admin page).

Comments

c960657’s picture

Status: Active » Needs work

I agree - this function could benefit from using a cache.

I suggest you move the cache_get() logic inside the if (!isset($cache)) { block.

I suggest that you rename the existing $cache variable used for holding the result array to e.g. $ini or $return, and then use $cache exclusively for holding the cache object returned by cache_get(). This naming convention seems more in line with Drupal core. Reusing variable names makes the code hard to read.

Please also remove the "// NEW ..." comments from the patch. These are not necessary. Using a cache in this way is fairly obvious, so I don't think there is a need for elaborate comments.

c960657’s picture

Version: 6.x-1.2 » 7.x-1.x-dev

Oh, and please create the patch for the 7.x version of the module. Once it has been applied to 7.x, we can backport it to the 6.x version.

m_z’s picture

@c960657: thanks for your answer

Are you a maintainer of this module?
My suggested patch was intended to give an idea how the advanced_help module's performance could be improved. So I tried to make only small modifications to make it clear what is needed to increase performance. Since I don't use the 7.x advanced_help module and due to time limitations, I won't modify my initial patch.

@c960657 or anybody else: Feel free to change the patch above (see #1). I would welcome seeing it in a next release.

c960657’s picture

Status: Needs work » Needs review
StatusFileSize
new4.46 KB

No, I am not the maintainer - just a user who noticed the performance issue.

Here is a patch for 7.x.

c960657’s picture

StatusFileSize
new4.37 KB

And a D6 backport.

m_z’s picture

@c960657: I reviewed your code and it looks ok --> maybe another user could test your patch (especially for the 7.x version) to make this issue "rtbc"

Your modifications in advanced_help_get_topics() and advanced_help_get_settings() are unnecessary in my opinion, but maybe it is more straightforward to switch to "your" $ini variable name also in this 2 functions.
Many thanks for your effort.
I would like to see the patches in future relases.

c960657’s picture

I renamed $cache to $ini in advanced_help_get_topics() and advanced_help_get_settings() for the sake of consistency. I think it makes the code more difficult to read if $cache in one place contains a cache object and in another closely related function it contains an array.

m_z’s picture

I found that there must be language specific cache IDs for proper working in multi-language Drupal sites.

So all you have to do is adding
$GLOBALS['language']->language
at the end of the $cid parameter of each cache_get() or cache_set() call.

For my initial patch the new lines must look so:

function _advanced_help_parse_ini() {
  static $cache = NULL;

  // NEW: Try to find $cache array in cache table.
  if (!isset($cache)) {
    $cache = cache_get('advanced_help_parse_ini_'. $GLOBALS['language']->language);
    if (!empty($cache->data)) {
      $cache = $cache->data;
    }
    else {
      unset($cache);
    }
  }
  // END NEW: Go on with old (expensive) file detection if no cached value could be found.
  if (!isset($cache)) {
    ...
    drupal_alter('advanced_help_topic_info', $cache);
    // NEW: Store $cache array in cache table.
    cache_set('advanced_help_parse_ini_'. $GLOBALS['language']->language, $cache);
  }
  return $cache;
}
c960657’s picture

StatusFileSize
new4.66 KB
new4.75 KB

Good catch. Here are updated patches.

m_z’s picture

Has anybody tested these patches?

c960657’s picture

I have been running the D6 patch on a large production site for some time now. But we don't use advanced help a lot.

m_z’s picture

I also run the D6 patch successfully since some months, so issue status should be changed to "rtbc", right?

c960657’s picture

It would be nice to get some feedback (review or testing) on the D7 patch also.

m_z’s picture

It seems that our performance improvement isn't a big topic of interest in the community... ;-)

I reviewed the Drupal 7 patch and see no problems. It looks fine.
So ready for "rtbc"? I would say "yes".

c960657’s picture

Status: Needs review » Reviewed & tested by the community

Yes, I agree.

joshmiller’s picture

This patch is now a part of the Commerce Kickstart 2 distribution... thanks for the performance bump :)

#1708072: Apply a patch to advanced help for performance

das-peter’s picture

+1 for that! I've just profiled configuring a views field and advanced help "wastes" nearly one third of the processing time.

redndahead’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

This patch no longer applies in d7. Could we get a re-roll?

das-peter’s picture

Status: Needs work » Needs review
StatusFileSize
new4.61 KB

Re-rolled D7 patch.

redndahead’s picture

Can someone test this re-roll and mark it as RTBC? After this one is RTBC then I'll commit it and do a 1.1 release.

sherakama’s picture

Status: Needs review » Reviewed & tested by the community

Tested patch in #19 against latest dev and issue seems to be resolved.

Please proceed with stable release.

redndahead’s picture

Status: Reviewed & tested by the community » Fixed

This has been committed. thanks

Status: Fixed » Closed (fixed)

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