On a site with a large menu there can be many url_alias queries. Now, at 1ms or less per query, individually they aren't a big deal, but even modest sites quickly get 30-40 of them on every page hit, and I can envision scenarios where you might see hundreds of them.

My solution is to create a cache that keeps the ones that get hit a lot, without burdening the system for the ones that get hit less often.

This patch is, at the moment, incomplete, but I wanted to get some community evaluation before I put the niceties on it.

It needs:

  • Documentation of the functions that were added
  • a form field in system_settings to control the cache size

This patch caches the url_alias map, and additionally keeps the last time a given alias was hit. It writes the cache on page exit; when it does so, if the number of items in the cache exceeds the threshold (defaulting to 500 items), it prunes items least recently hit first. This means that items that appear commonly on menus, that are hit often, will remain; items that are hit only on some nodes will quickly get pruned off.

On my test site this has the effect of shaving about 70ms off of every page view -- this is very significant on light pages, and of minor but still important significance on heavy pages.

I'd love to see a few people try this out and see what they thing, and ensure that my implementation is correct.

CommentFileSizeAuthor
cache-url-alias.patch3.37 KBmerlinofchaos
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

Oh yes, one addition:

The system needs to update the cache (or invalidate it) when path aliases are modified; that also is missing from this patch.

Dries’s picture

Code style nit: we try not to glue words together (lasthit) and try not to abbreviate words.

Did you benchmark this?

Wesley Tanaka’s picture

Status: Needs review » Closed (duplicate)

This has previously been reported here: http://drupal.org/node/40860

Dries’s picture

Version: 4.7.0-beta4 » 4.7.2