What Does Node.js Mean for WordPress?

Node.js

If you are a fan of PHP for developing web applications (as I am), you could feel the world shift a bit as it was announced that WordPress was switching from PHP to Node.js*. 

Don’t think of WordPress as a blog engine. Think of it as an open source Content Management System (CMS). As such, it provides the code for a significant part of the web. I’ve heard that anywhere between 25 and 30% of the world’s websites are powered by WordPress. So a serious change to WordPress means a significant change to the web.

WordPress also sets the standard for PHP performance. There is an open source benchmark available for different releases of WordPress which works for both PHP and Facebook’s open source PHP alternative, HHVM. The PHP and HHVM open source communities compete on who has the best performance on this WordPress benchmark. It’s not the only comparison, but it’s one that gets noticed.

Upon further reading it turns out that only the WordPress administration interface has been changed to Node.jsfrom PHP.  The WordPress core engine remains in PHP and is unlikely to change soon.  This is because of a rich ecosystem of WordPress plug-ins, which have maintained compatibility for something like five years.

What does Node.js have going for it which makes it attractive for WordPress as an alternative to PHP? I talked with our Node.js lead, Uttam Pawar, who has worked on both PHP and Node and he gave up a list of advantages:

  • Pages are rendered on the client rather than the server.  This is particularly noticeable for an interactive page like the administration interface of WordPress. So as one clicks around in the web interface, you don’t need a network round trip with the server to get a response to clicks.
  • Code is cached on the client.  Communication between client and server can be with JSON objects. This means that on a slow network connection you should see better performance. I’m writing this blog entry on an airplane with a typically slow wifi connection. However the WordPress.com administration interface is noticeably faster than it would have been otherwise.
  • Server code in Node.js is written in JavaScript*.  This means that code on the server primarily takes advantage of the V8 JavaScript engine, which has been shepherded very well by Google and the community. Significant community contributions by Intel and others have improved V8’s performance which benefits Node.js users. Note that most of Intel’s work has focused on client JavaScript performance. Our studies have shown some interesting opportunities in the server space for V8, which Intel is investing in now.
  • The new Node.js WordPress code can take advantage of the V8 JIT.  This “Just In Time” compiler https://software.intel.com/en-us/blogs/2015/09/10/the-jitter-conundrum-just-in-time-for-your-traffic-jam  means that JavaScript code which is run frequently is translated into native code. Interpreted languages, such as Python, Java, PHP and JavaScript will typically run much faster if so-called “hot” code paths are translated into native instructions and executed. The open source HHVM interpreter for the PHP language also has a JIT which benefits performance, so this is not unique to Node.js.
  • Users still get a choice of implementations.  One of the coolest aspects of WordPress (and a number of other major PHP web apps) is that you can choose from more than one implementation of PHP to run it. Facebook has developed HHVM to run its massively popular website, and WordPress runs on HHVM as well as the original PHP project. Both are open source and actively maintained and developed. (And we are huge fans of both.)  Microsoft recently submitted a patch to Node to enable it to run Chakra, their competing JavaScript engine.  Although the patch is frankly enormous (over 14,000 lines!), once it goes through the review process it will enable a second choice for Node users.

Will the core of WordPress ever move from PHP to Node.js? They would certainly need to figure out a way to support the WordPress plugin legacy. But a future RESTful API for the WordPress core might constitute a further move away from PHP.

For more complete information about compiler optimizations, see our Optimization Notice.