Speeding up WordPress home page
After about an year, since we launched Asianet News Portal the home page with all the complications had started to show a dead slow performance, and by using our Query Profiler, I could identify the bottleneck as the number of queries, and wordpress itself was telling the status as 48 queries in 6.344 seconds. Now this was a whopping value, and when the latency of 2 to 3 seconds is added to this, the initial html load would be in 9 seconds. Making the total site complete load in about 53 seconds. One can imagine the agony I was feeling, after all the work I had done to get backlinks, and if users who are visiting the site is just running away without waiting for the site to load, then I better not run the site atall.
I knew that all hope was not lost. Digging into the plugin documentations, identified some of the events which was fired after a post was saved, namely edit_post, and publish_post. Using this trigger, I created an updated cache of the homepage, just a serialized associative array of indexed hotareas, written to the ramdisk (/dev/shm). Changed the theme home.php to check there first, and if the file exists, the filemtime is the sites modification time, and the content is picked, unserialized and used to build the homepage. And the result is 7 queries in 0.195 seconds. Wow.. the page load is latency plus generation time means I saved about 7 seconds in the total time.