Turning off aliasing in l()

It is always a good things when a site grows large enough to worry about performance issues. With more users and longer reports, one site I regularly work on was having an issue building a reservation report page. Quickly I turned on Devel with its query log, checked the main query that builds the report, put it through EXPLAIN and optimized a few keys. But no real improvement was made.

So I looked again at the query log, and noticed that drupal_lookup_path() was being called 1000 times (as many results in the report, and yes the Project manager wants them all on one page). So I am making 1000+ individual queries to the url_alias table, each taking only a few ms, but added together it is slowing down the report.

This is what the offending line looks like:

... = l($reservation_id, 'reservation/info/'. $reservation_id);

I finally realized that I don't need aliasing on those links. They simply link to the information page of a particular reservation (reservation/info/34038) which will never, and should never be aliased.

Now my code looks like:

... = l($reservation_id, 'reservation/info/'. $reservation_id, array('alias' => TRUE));

A months worth of data now renders in seconds, instead of over a minute.

A rule of thumb I am thinking of using is a Task Oriented versus Content Oriented links mentality. If a link is solely for transitory or task based activity (like creating or editing a comment) then it shouldn't even try to be aliased.

A perfect example are all the edit links on the node and comment administration pages. Is anyone in their right mind going to create an alias for 'node/45/edit' or for 'comment/edit/1822'.

I am not saying you should turn off path aliasing everywhere, but for any page littered with task oriented links in the hundreds, it might really speed up your day to do so.