Code: Why Drupal is More Robust than WordPress in 2020.

Posted on 9 Jan 2020 by Alexei Raiu
Code: Why Drupal is More Robust than WordPress in 2020.

There are 3 aspects that make Drupal 8 more robust than WordPress code-wise: selective loading, quality, and caching. Generally the object-oriented code (OOP) is slower than the functional code, and having more code is slower than having less code. Drupal 8 has way more code than WordPress and it's OOP. So why did Drupal 8 beat WordPress by average 20% during my tests? Here's why.

1. Selective Loading.

Drupal 8 has a big code base. It integrates some of the best quality PHP libraries for it's internals, and it has lots of code. And if it would be slower, if it loaded all that code at once. But it doesn't. Object oriented programming (OOP) allows the code to be selectively loaded when they are needed for a given request. Thus, only the needed parts get loaded and ran. WordPress, being still procedural, has to load the whole code base into memory to make its functions available for being called. That's how larger code base of Drupal 8 is compensated by smart loading, allowing it to do better and more without overhead.

2. Quality of code.

The speed of code is greatly influenced by its quality. Having careless code, mixing markup, javascript, html, css in your php code makes the code bloated and hard to maintain. While technically, it would be faster to form strings of markup on the spot, without passing them to a template engine, there is a reason why mixing markup and business logic is considered a bad practice among the developers. Lack of due attention to quality and streamlining results in sloppy and bloated code, and in the end, makes the code slower than it could or should be. WordPress is pested with this malpractice, that can be found even at the most popular and highest-ranking plugins. Drupal, on the other hand, has gone out of its way to streamline the code and move markup into templates, css and javascript into attached libraries. Overall, average Drupal's ecosystem code is of much higher quality than that of WordPress ecosystem. This is also partly because of Drupal's steep learning curve, which is Drupal's weakness that feeds up into a strength in this case.

An example of a very popular WordPress plugin mixing JavaScript in a PHP static class function.
An example of a very popular WordPress plugin mixing JavaScript in a PHP static class function.

3. Caching.

You can get caching plugins for WordPress, true, but Drupal has caching out-of-the box. And Drupal's caching is way way better than WordPress caching. Why? Because to correctly cache content not only for visitors, but also for logged-in users, you need to have a smart system of triggers and checks that tell the caching system when and which cache to invalidate when the content is being edited. And second, you need to streamline the whole content data and render process through this caching system to have a good grip on it. Thus, Drupal's built-in content type and field system, together with streamlined templating system allows such caching level. WordPress, on the other hand, is architecturally incapable of supporting such level of caching, with it's markup often embedded in code, and content types and fields provided with plethora of disparate plugins, it can only bluntly cache pages for anonymous visitors (which is enough for simple sites).

Conclusion.

We previously discussed how Drupal has a more robust data architecture. Now we have discussed how Drupal has better code. I believe that if we join the data structure and the more robust code together, we will have a general explanation of why Drupal 8 performed on average 20% faster (TTFB time) than WordPress 5 during my tests.