I had been having a lot of trouble recently with the performance of my WordPress blog, and have been experiencing very slow WordPress page loads. Compared to Blogger (which I used to use), the ease of use and self publishing to my own host with WordPress is great, but since converting the page load times have slowed down exponentially. So I spent some time trying to track what exactly was making it so slow. There is never one specific answer for everyone’s problems, but here I’ll cover briefly what I’ve learned. (Also, remember to make sure your host is not having any problems!)
First of all, for anyone new to WordPress, you need to be aware that your entire site is pretty much database driven. In simple terms this means that there is no “physical page”, instead the data is all stored in the database and each time a “page” is requested, the server dynamically generates it and then returns it as the response. This is in contrast to Blogger (self published via FTP) which creates static html pages during publishing. This means that when using Blogger (I am still referring to self published Blogger) it is horribly slow to publish, because it needs to build the files, and also update any files that are also affected, such as your labels or tags pages. Of course the flip side to this publishing inefficiency is that page loading with static html is very quick, since server resource use is minimal. (Blogger self publishing is being discontinued and is precisely why I switched to WP, not to mention that now with WP I can add custom PHP scripts which I could never do with Blogger). Being that WordPress is data driven, it builds and renders the pages on the fly, allowing for lickety split publishing and allowing you to easily change your template without needing to republish, but results in more server resource usage and slower page load times.
So having explained that, let’s look at how to address some of these performance issues on a WordPress blog. Before beginning, you should be aware that WordPress has two functions which make performance tracking very easy. They are get_num_queries and timer_stop, and tell you the number of data queries performed and how long the page took to load, from the start of the wordpress code to the end.
- The first thing that most people recommend is checking your plugins since those can add a lot of data queries and resource overhead. As an example, I love Yet Another Related Post Plugin (YARPP), but be careful with it. I manually inserted it into the main index page as well as single pages, but have since removed it from the main page since it was causing a big performance hit.
- Which brings us to the next point. Anything you put in the loop on the main index page will execute multiple times, so don’t go crazy customizing like I did at first. Keep big data queries and custom logic out of the loop unless you know what you are doing. By adding YARPP to the main loop, it was executing for each of the 6 to 10 posts that the main page shows, resulting in that many extra database queries.
- Some people will tell you to take out any extra “fluff” PHP code, substituting in static code if at all possible, though I personally don’t think this is an issue because all my non-WP pages are PHP also and they load very fast. But it’s worth being aware of, and while you’re looking, try to minimize any unnecessary data queries. Putting in static code instead of an unnecessary data query might help. Probably not just one, but if you find a lot it wouldn’t hurt.
- Regarding plugins and other third party tools, be careful of any that connect back to their own domain. This is probably ok if it happens on a user action like a click, but you certainly don’t want this on your page load. I had the Share This widget, and it really slowed things down since I think it was connecting back to its own servers. But the Add This widget seems ok as it is just an embedded Javascript with action that only occurs on click. At least I’m pretty sure. Either way, the Add This script works for me, but Share This just wasn’t worth the performance hit I was seeing.
- Watch out if you use a Twitter widget, depending how it’s coded, sometimes it will hold up the loading of your page while it tries to retrieve your latest tweets to display
- One thing that surprised me was the built in WordPress widgets. Even though the Popular Tags widget only did one query, for some reason it seemed like it took longer than it should. The Topic widget seemed a little better though. And the other surprising one was the Links widget, that seemed to be a little slower as well. I’ve got them all on the site now, and they seem to be ok, but just test it on your own site. If you have a lot of tags or links this would probably slow it down compared to only having a few
- A less likely culprit, consider your web host. Do you have a dedicated server, are you sharing resources, is your MySql install configured properly? I was able to tell that it wasn’t an issue with my host, since I’ve got other PHP pages that load fine, and also run another site that uses MySql with no performance implications.
- Using a caching plugin will help for sure, though I don’t recommend installing one until you have addressed any glaring performance issues. Since the cache is on a page basis, it means that the first person to attempt to load a page will have to suffer through a slow load time if the performance is bad. But of course once you’ve got it figured out, a caching plugin will make it even faster. I have WP Super Cache installed, but have it disabled so I can track the true performance of my server.
What it comes down to is finding what works for your own install. What may be killing one person’s site may be fine on yours. It could be any or all of the following: your server (host) resources, your PHP/MySql versions, database size and table row counts, what widgets you use, third party plugins, and custom code in your template.
The bottom line is that your performance will be unique to your system and your site, so run some tests to see where your bottleneck is. And remember, it may take patience and time.
- See more about me and Idealist Cafe
- Add Idealist Cafe to your feed reader
- Or maybe sign up to get free updates by email
- Liking Idealist Cafe on Facebook is a good option
- Catch more frequent and random updates on Twitter
- Just reading this article is cool too! :)
Originally posted on Saturday, March 20th, 2010 at 6:45 AM .
The suggestion about watching what you put in the main page loop is actually rather clever. I could kick myself for not having paid attention to that when working on my site. I will have to go back and take a closer look at what has been added there over the years. 🙂
When I first converted to WP, I was just adding tweaks everywhere. Then I realized that my pages were sometimes taking 5 or 10 seconds to load, and the fact that I added some features and data lookups to the loop on the main page was one of big problems. I guess that’s the beauty and the downside to WordPress. You can customize anything, but having such freedom also gives you the ability to kill your site too 🙂