qTranslate plugin performance optimization

Installing a qTranslate, multi-language enabling WordPress plugin, can increase the time in which your blog loads.

My installation of the blog, with all the plugins (including qTranslate), loads in about 600ms. Disabling qTranslate reduces the load time to 320ms.

To see what is happening I installed Xdebug and WebGrind for making a performance review of WordPress and qTranslate. Xdebug is probably a package in your Linux distribution (at least it comes with Ubuntu Server as php5-xdebug). Instructions for installation and usage can be found here.

And the WebGrind screenshot:
qtranslate default install

As you can see, function named “qtrans_use” takes 20% of all loading time. Combined with all “qtrans*” functions, the share goes to more than 30%. That is really inefficient compared to the analysis with qTranslate disabled – note that the loading times are lot longer with Xdebug enabled:
qtranslate disabled

As none of those two options are satisfactory, I tried to optimize qTranslate. Expanding “qtrans_use” function reveals that 48% of calls are recursive (function calls itself) and for 38% a function “qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage” is to blame:
qtranslate default install qtrans_use expanded

After a little searching I found out that WordPress options are getting translated too. Unfortunately there is no cache implemented to remember the translations so the whole list gets translated every time one option is called. So I disabled (just put a # or // in front) the line “add_filter (‘option_’.$option, ‘qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage’, 0);” in “qtranslate_core.php”, which is located in “wp-content/plugins/qtranslate”. This improved the loading times a bit – to 480ms. A 120ms improvement. Not much, but it helps when a Google crawler goes through hundreds of pages.

qtranslate optimized

You can see that number of calls of “qtrans_use” were reduced form 13517 to 2221. qTranslate now contributes little more than 12% to the whole loading time. There is some room for improvement, but probably this includes substantial modifying of the plugin. You must also know, that some plugins can have their options translated and in that case add a little “if” conditional clause around that “add_filter” call to let only the desired options through.

  1. Thank you for the post, this is very useful!

    We had performance issues on our WordPress site and with a benchmark realized that qTranslate is the culprit.

    Commenting out that entire block makes it much faster: http://screencast.com/t/bY2HC6GLFoDB

    All the best,
    Antonie

Leave a Comment





NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>