Slow Drupal node edit pages? Token tree is slowing you down..

For quite some time one of the items I wanted to improve was the responsiveness of our content edit pages. The server response time was fast (after a performance patch I posted here for the term reference tree module - http://drupal.org/node/1966370), but the biggest hold up was with the browser rendering of token trees:

Token Tree

If your node edit pages (e.g. /node/add/article) have a lot of fields that can contain references to other entities (e.g. a node reference field that can reference another content type, which in turn can reference another content type -- you get the picture) you need to be aware of recursion if you have any token tree elements on your page. The token tree will recurse through the entire hiearchy to find candidate tokens. The symptoms in our case were heavy browser lag while the rendering of the token tree took place.

There's actually an easy fix for this, but it's not very obvious. Internally, the token module will attempt to read a variable to determine the level of recursion. By default this is 4. You can override this in a process hook like so in your theme:

<?php
function my_theme_process_token_tree(&$variables)
{
 
$variables['recursion_limit'] = variable_get('token_recursion_limit', 4);
}
?>

Be sure to replace the "my_theme" with your theme machine name and clear caches to reload the theme registry. The nice part about this optimization is it fixes all uses of the token tree. We also use the DFP module for advertising and it, too, uses a token tree. Optimization++ ! Good luck in your tuning endeavors!

Topics: