Many of our clients don’t like the paged comments feature of WordPress as they like to have all the keywords occurring in the comments present on our article page and not spread across multiple pages. Keeping thousands of fresh comments on the page with every possible combination of keywords helps them rank at the top of Google for very competitive product categories.
However the downside is that it doesn’t work for administrators and that the cache has to be purged and rebuilt when comments are added or removed. It’s also usually slows down logged in users as we move more and more of our clients over to a membership or at least logged in user model.
Quest of speeding up the comments display
We sought alternative ways of speeding up the comments by simplifying the PHP code required to display each comment. Here are all the filters running on comment text and how much they contribute to the total PHP processing time for comments.
Filter Name
Description
Required
wptexturize
Converts regular quotes to fancy quotes etc.
No, it’s eyecandy
convert_chars
Escapes HTML special chars.
Yes
make_clickable
Makes the plain text links clickable.
Yes
force_balance_tags
Makes sure HTML in comment text won’t break the page layout.
Yes
convert_smilies
Converts text smileys to Emojis
No!
wpautop
Puts in paragraph breaks.
Yes
In our test enviromnent 781 comments take ~1.52 seconds to display. When all of the above filters are disabled, it’s ~1.35 seconds (12% gain) and when the absolutely needed filters are kept (without them the comment wouldn’t appear properly – no links or line breaks) it’s ~1.43 seconds (6% gain). So that’s not much.
Comment with all filters
Comment with just the required filters
Comment author, date, etc.
Big part of comment HTML are the meta information. We checked how much could be saved on each by removing that part of markup and found the issues:
Information
Description of the issue
Estimate of savings
Comment Date
It’s called 3 times for each comment with a lot of formatting going on
13%
Comment Link
The link is mostly just the ID of the element
12%
Edit Link
Comment editing permissions are checked for each comment
7%
With all of these improvements and reduced comment text filtering 781 comments on our test post load in ~ 0.986 seconds (35% speed increase).
These improvements could be implemented in a form of a simplified comment display callback function – Documentation on WordPress.org.
Fragment caching
The speed benefits of the above are clear, and they do help. We would still like to make the comment load not 35% faster, but lightning fast.
We tried to cache each comment individually rather than caching the whole list of comments. Advantages of this approach would be:
cache doesn’t have to be cleared when
posting a new comment
removing a comment
approving a comment
and so on
same cache files could be used for admins – just the “Edit” comment link would have to be put in using JavaScript
We would like this new function to work as seamless as possible, so we checked where it could be stored – here is are the average speed values for comparison of different comment caching options.
Caching mode
First load [s]
Repeated loads [ms]
no caching
1.655
single file
1.716
46
comment meta
3.2
46.6
custom database table
2.8
28
individual file for each comment
2.014
42
Single file – this is that’s currently done in FV Thoughtful Comments
Comment meta – much slower than caching into a file, unfortunately. We confirmed this on two different servers with different Apache + MySQL configs
Custom database table – faster than using comment meta, but all the database inserts still take its toll. Also, not sure why the display here would be faster than the other caching models, but we were able to replicate the behavior or different servers
Individual file for each comment – unfortunately still slower than using a single cache file. We are not sure about all the implications of this for multiple webhead website serving, but this is probably the solution for us.
Other interesting options might be using Memcache or Redis. However this kind of cached data should have a very long TTL. So the most resilient yet very high performance model is to cache each comment separately. Which is what we are going to do in the latest Thoughtful Comments
Martin graduated as an engineer in Computer Science from Slovak Technical University in Bratislava. He grew up in Liptovský Mikuláš in northern Slovakia next to the beautiful Tatra mountains. He is the developer behind our FV Player.
This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
Necessary Cookies
Strictly Necessary Cookie allow you to log in and download your software or post to forums.
We use the WordPress login cookie and the session cookie.
If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.
Support Cookies
Foliovision.com uses self-hosted Rocket.chat and self-hosted Freescout support desk to provide support for FV Player users. These cookies allow our visitors to chat with us and/or submit support tickets.
We are delighted to recommend self-hosted Rocket.chat and especially Freescout to other privacy-conscious independent publishers who would prefer to self-host support.
Please enable Strictly Necessary Cookies first so that we can save your preferences!
3rd Party Cookies
This website uses Google Analytics and Statcounter to collect anonymous information such as the number of visitors to the site, and the most popular pages.
Keeping this cookie enabled helps us to improve our website.
We reluctantly use Google Analytics as it helps us to test FV Player against popular Google Analytics features. Feel free to turn off these cookies if they make you feel uncomfortable.
Statcounter is an independent Irish stats service which we have been using since the beginning of recorded time, sixteen years ago.
Please enable Strictly Necessary Cookies first so that we can save your preferences!
Thankss… very helpful.