Views 1.5.1 with a Huge Performance Boost

   Amir

February 5, 2014

Views 1.5.1 started as a small maintenance release, with no thrills and nothing major. By pure chance, we discovered a huge potential for performance improvement. After a lot of work on internal caching, Views 1.5.1 delivers up to 400% improvement in your site’s performance.

How WordPress caches posts, custom fields and taxonomy

WordPress uses an internal and auto-triggered cache for posts, custom fields and taxonomy. It’s all working using the WP Object Cache object (not to be confused with page caching plugins).

When you query posts, WordPress intelligently saves the entire records of these posts, together with all associated postmeta (custom fields) and taxonomy (tags and categories), in the built-in object cache.

Then, when objects are rendered, they are loaded from the cache, rather than from the database. As long as you use the WordPress API to load content, things are loaded only once and reused during the render process. Neat, isn’t it?

Views 1.5.1 uses the WordPress cache too

Views and Types now do the same. When a View loads content from the database, it also pre-fetches all related fields and taxonomy and saves everything in the WP Cache, similarly to how the native WordPress API functions work.

Then, as you display these fields using shortcodes, Types and Views first check the cache. If it’s there (which is always almost true), it gets quickly loaded from the cache, without causing additional database load.

What’s faster, a site with Views or custom PHP?

As of Views 1.5.1, our testing shows that it’s basically the same. If you don’t go into any extremes, a site built with Views will take similar queries to a site built with plain PHP. There are only a handful of queries, needed to load the View itself. That’s usually completely negligible, compared to the actual content.

Please keep in mind that using a caching plugin is still a very good idea. No matter if you’re using Views or not, WordPress still takes considerable CPU to render a page. A caching plugin will save the page content as a static file and serve it with minimal effort.

Some numbers

For numbers, we selected pages from our very own site. We’re checking on our homepage, the Google maps demo page and the user guides page.

All of these pages include Views. Of course, we’re displaying everything using Content Templates.

The Google maps demo page is especially interesting because it includes several Views, each iterating through a large number of items (our team members) and displaying the results using different Content Templates. We use one template for the map-sidebar display and another one to fill the JS array that goes to the Google map. That page loads and displays a LOT of data.

Our Users Guide page includes nested Views. We first loop through the different products, then through the documentation topics for each. There are a lot of links to documentation items on that page.

Here is what we measured before and after the upgrade to Views 1.5.1.

wp-types.com homepage Google maps page User guides
Queries CPU time Queries CPU time Queries CPU time
Before optimization 423 2.72 sec 1076 9.0 sec 1093 5.1 sec
After optimization 382 2.29 sec 540 3.7 sec 940 3.76 sec
Improvement 10% 18% 99% 143% 16% 35%

* Please note that for this to work, you’ll also need to upgrade Types plugin. The new caching requires Types 1.5.4, which was released last week.

** Our site also uses WPML. We added similar caching for WPML’s language tables, which boost WPML’s performance by about 100%. The numbers above include WPML 3.1, which comes with this caching too.

Other major new features in Views 1.5.1

We used this opportunity to include several other notable improvements to Views:

  • New filter – “wpv_filter_post_excerpt” – lets you customize the excerpt for posts.
  • New filters – “wpv_filter_start_filter_form” and “wpv_filter_end_filter_form” – let you customize the beginning and end of the View filter section.
  • New filter – “wpv_filter_content_template_output” – let you capture and customize the output of Content Templates.
  • New shortcode {{wpv-post-class add=””}} – lets you display the post class in templates (we use that in our WooCommerce Views reference site, out very soon)
  • New options for the ‘output’ attribute – output=”normal|raw|inherit” – for the {{wpv-post-body view_template=”None”}} shortcode.
  • New improvements the {{wpv-post-excerpt}} shortcode:
    • The length attribute now applies to real excerpts too.
    • Added a new count=”char|word” attribute.
    • Added a new ‘more’ attribute.
  • New: {{wpv-user}} shortcode can take ID as the field attribute value.

Bugs fixed in Views 1.5.1

No release is truly complete without crushing some bugs. Here is list of bugs handled in this release.

  • Fields created outside Types and then added to Types control as numeric were not sorting a View as numeric values.
  • Fixed error that appeared when creating a Content Template on the Templates listing page if unchecking all the options offered in the popup.
  • Fixed error when rendering a Content Template with auto formatting inside a View with AJAX pagination.
  • Fixed a problem causing “shop_order_status” taxonomy to hijack the “post_tag” taxonomy on the V icon popup when using WooCommerce.
  • Fixed a problem that prevented using quotes in custom search values, both in search boxes and in custom fields using textfield.
  • Inner shortcodes inside Templates used calling {{wpv-post-body}} with the attribute suppress_filters set to true were not being rendered.
  • Moved the custom CSS output earlier in the wp_footer hoot, before the script printing at 10, to avoid bottlenecks.
  • Raiseed the z-index for the V popup in the Content Templates edit screen to avoid CodeMirror gutters and scroll bars problems.
  • Fixed a problem that caused the pagination summary to display wrong data.
  • Fixed a ‘PHP fatal error’ when adding debug info for a taxonomy filter by terms coming from the current page.
  • Fixed an error when filtering by taxonomy set by the current page – the passed terms array was not correctly indexed.
  • Preload last page when doing AJAX pagination using Slide Down or Slide Right effects.
  • Cleaned the get_users_query() function to make it modular by using filter hooks in “wpv_filter_user_query”.
  • Changed some setting for WordPress Archives, so it doesn’t delete all the Views Settings options from the database.
  • Fixed a problem that caused offset not to work on Views listing posts if there is no limit or pagination setting.
  • Fixed a problem that caused offset not work on Views listing users if there is no limit setting.
  • Fixed a problem with Views duplication, which could lead to a View with status of “future”.
  • Fixed export error on layout wizard settings for Views created using an older version.
  • Fixed an error on the disable_rich_edit_for_views() function in scenarios where the $post is not already set.
  • Fixed a problem causing Content Templates attached to a View to be lost on the export/import flow.

All these issues were happening in very specific circumstances. We highly appreciate your patience in working with us to resolve these problems.

Download and upgrade

As always, the easiest way to get this update is using our Installer plugin. You can also download updates manually from your Toolset account, under the Downloads section.

Make sure that both Types, Views and Access are updated. If you’re using WPML, get WPML 3.1 in a few days. All received big performance updates.

Coming next to Views

Juan, Views lead developer, is about halfway through implementing dependent values for custom searches. We started this project with a lot of uncertainty but now it’s going great.

The end result will be Views custom searches, which automatically limit the available filter options according to what returns results. You’ll also get a new shortcode which lets you display how many results match each filter option.

The best thing about it is the simplicity of usage. All it takes to enable this powerful new feature is a single click in the View settings. Everything else will happen automatically for you.

We haven’t forgotten about easier support for parent/child relationships. We’ll get there too 🙂

Ideas? Suggestions? Questions? Leave your comments and we’ll get back to you.

 

Comments 13 Responses

  1. Amir, this point update is greatly welcome. Performance in sites built with Views has been a major concern for me.
    I’m going to test it right away and post what I find.
    BTW, I’m looking forward those two anticipated features, auto-updating parametric search filters and many-to-many relationships. Any rough estimate for these to arrive?

  2. It’s great to see more filters are being added to Views constantly. This is better than hacking core code 🙂

  3. These results are impressive, congratulations! This is by far the best WP plugin I’ve ever bought.
    A suggestion: I’d like to have a “no duplication filter” to avoid the display of the same post multiple times in the same page.
    I use many widgets to show latest posts, featured posts, posts in the same category, etc… and often a post is displayed multiple times. It would be great to have a checkbox in Views widgets where to select if posts already present in the same page must be skipped or not. Is this feasible?

      • No, I meant exactly the opposite.
        I’d like to exclude from one view the results displayed by any other view in the same page.

  4. Great work folks, I really appreciate your consistent efforts. Just need CRED to have a better WYSIWYG editor (with blockquotes!) and all will be perfect 🙂

    Cheers, Mark

  5. This update actually doubled (!) the queries for one of my views.

    From 150 queries to 280.

    Many other of my views have slightly more queries also (4-8 per view)

    This is not great for me. 🙁

    • Of course, this shouldn’t happen. Are you also using the recent version of Types? What other plugins are you using?

  6. This update was bad news for me. Trying to fix the site now. Can I download a previous version somewhere?

    • You can get all previous versions for all our plugins from the Downloads page. Login to your wp-types.com account and click on Downloads. Click on the ‘changelog’ link next to the plugin you want and you’ll see all previous versions.

      We would very much like to help you resolve the problem. Can you open a support thread and tell us what’s wrong? If you can paste the link to that thread here, I’ll make sure that it gets to the right person with priority. Please be sure to report what plugins you use and what versions they are.