
By James Meickle | Article Rating: |
|
September 17, 2013 05:00 PM EDT | Reads: |
14,930 |

This is part 4 in a 5-part series on performance in the upcoming Drupal 8. Check out part 3, on performance in Twig templating, here.
Views is one of the most installed Drupal modules with over two thirds of Drupal sites reporting that they have it installed. Soon, though, that number will go up: as of Drupal 8, Views is a core module! This effort started as a community effort and was announced as an official Drupal 8 initiative in a post by Dries explaining why this change is so exciting.
One of the reasons that Views is so popular is that it provides an ‘all-in-one' answer without writing a single line of code. But there's a reason that many programmers hate WYSIWYG editors: you see the result, but not the steps taken to produce it, and what you don't know might come back to bite you. While a WYSIWYG editor will get you broken links or weird formatting, WYSIWYG data retrieval can have direct performance implications. A'straightforward' View might fetch data in unexpected ways, and even ‘small' changes like adding a node relationship can result in radically different queries. Worse, any scalability issues may only manifest when a View is run against production-like data. A View focusing on user content might start choking on a user who favorites hundreds of nodes instead of the five you tested with.
That's not to say that there's anything wrong with Views, as this problem is very common in ORMs in frameworks such as Django and Rails. In fact, because Views is more all-encompassing, it provides effective out-of-the-box solutions to some of these problems in the form of result, block, and page caching. However, Views aren't cached by default, and even with Devel integration it provides minimal data on its performance.
Rather than using a profiler or debugger, it's possible to monitor Views performance by integrating with its code. Structurally, Views can be broken down into a ‘build-execute-render' pipeline. In Drupal 7, many hooks are available for interacting with this process and changing how Views are constructed. There have been many Views API changes over time, but this basic set of hooks can be used on Drupal 6 and 7 sites, and Drupal 8 continues that trend. The TraceView Drupal module implements these hooks to track time spent in Views:
The Views rendering step takes less time in Drupal 8 than in Drupal 7 because it is no longer responsible for generating HTML.
Examining identical Views in Drupal 7 and 8 reveals that less time is spent in the render step of the pipeline. The codebase has been extensively refactored, so comparing backtraces would be difficult, but I've already examined this discrepancy using TraceView in my last article about Twig, the new templating engine in Drupal 8. The Views pipeline still exists in Drupal 8, but the render step no longer generates the View's HTML, meaning that the performance of a View has to be placed in the context of the rest of the request.
When I wrote about Twig, though, I didn't cover more advanced use cases for Views. There are often multiple Views on a page, or sometimes even multiple displays from the same View. To compare how this works in Drupal 7 vs. Drupal 8, I made identical setups by creating nodes with Devel Generate, enabling the Archive and Recent Comments Views, and placing their blocks in a sidebar. Here are traces generated by visiting the full page version of the Archive:
A request to Drupal 7, with a segment of time spent in Views highlighted in white.
A request to the same configuration in Drupal 8, again with a portion of Views time highlighted in white. Drupal 8 performs much more initialization work before entering Views, and Twig rendering and cache setting afterwards.
Published September 17, 2013 Reads 14,930
Copyright © 2013 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By James Meickle
James started as a hobbyist web developer, even though his academic background is in social psychology and political science. Lately his interests as a professional Drupal developer have migrated towards performance, security, and automation. His favorite languages is Python, his favorite editor is Sublime, and his favorite game is Dwarf Fortress.
![]() Dec. 23, 2017 12:00 PM EST Reads: 2,037 |
By Pat Romanski ![]() Dec. 23, 2017 10:00 AM EST Reads: 663 |
By Elizabeth White ![]() Dec. 23, 2017 10:00 AM EST Reads: 1,095 |
By Liz McMillan ![]() Dec. 23, 2017 08:45 AM EST Reads: 1,166 |
By Liz McMillan ![]() Dec. 23, 2017 08:15 AM EST Reads: 2,152 |
By Elizabeth White ![]() Dec. 22, 2017 11:00 AM EST Reads: 982 |
By Pat Romanski ![]() Dec. 22, 2017 09:30 AM EST Reads: 3,018 |
By Elizabeth White ![]() Dec. 21, 2017 06:00 PM EST Reads: 1,148 |
By Pat Romanski ![]() Dec. 21, 2017 04:15 AM EST Reads: 13,724 |
By Elizabeth White ![]() Dec. 18, 2017 03:45 PM EST Reads: 2,281 |
By Elizabeth White ![]() Dec. 18, 2017 01:30 PM EST Reads: 2,293 |
By Elizabeth White ![]() Dec. 18, 2017 01:00 PM EST Reads: 4,077 |
By Liz McMillan ![]() Dec. 17, 2017 04:00 PM EST Reads: 1,243 |
By Pat Romanski ![]() Dec. 17, 2017 02:00 PM EST Reads: 1,332 |
By Elizabeth White ![]() Dec. 17, 2017 10:00 AM EST Reads: 1,378 |
By Liz McMillan ![]() Dec. 15, 2017 11:00 AM EST Reads: 2,295 |
By Elizabeth White ![]() Dec. 14, 2017 04:00 PM EST Reads: 1,472 |
By Liz McMillan ![]() Dec. 14, 2017 11:45 AM EST Reads: 1,531 |
By Elizabeth White ![]() Dec. 14, 2017 11:00 AM EST Reads: 1,512 |
By Pat Romanski ![]() Dec. 13, 2017 02:00 PM EST Reads: 1,307 |