15

Background

jade syntax is awesome but i wanted to see how it was affecting performance.

So i created a single page app and used apache bench to compare its throughput using jade to render a page vs using an in memory string. There were no variables so this was a purely academic comparison.

The in memory string made the entire app more than twice as fast locally, which seems a lot considering jade in production mode should be rendering from an in memory cache.

I'm using node 0.8 and the version 2.5.11 of express in production mode with the view cache option explicitly set to true.

apache bench results: https://dl.dropbox.com/u/3737990/jade/jade.png https://dl.dropbox.com/u/3737990/jade/memory.png

Max Desiatov
  • 5,087
  • 3
  • 48
  • 56
alzclarke
  • 1,725
  • 2
  • 17
  • 20

3 Answers3

9

As mentioned by Harry, it's meaningless to compare a template engine's performance to the performance of sending a string, since those address two different needs. It's somewhat like comparing the MPG of two cars, except one car you just put into neutral and let it roll down a hill.

Instead, it is much more helpful to compare templating engines, since they are all means to the same ends (dynamically rendered HTML).

Here we see that Jade is the slowest templating language. There are probably a lot of factors that play in to why this is the case, but the core issue is that Jade wasn't designed for speed. If you need extremely high performance, doT was designed for speed.

Community
  • 1
  • 1
josh3736
  • 139,160
  • 33
  • 216
  • 263
  • 6
    The jade in that demo hasn't been set to 'production mode'. The comparison is worthless. – Harry Jul 17 '12 at 14:46
  • I'm not totally sure as I don't have the benchmarks on me right now, but Jade is either the second or third fastest on that list. Of course nothing beats doT as it's essentially just a string concat. – Harry Jul 17 '12 at 14:59
  • doesn't production mode only apply to jade in express? the demo is using the raw jade implementation – alzclarke Aug 09 '12 at 11:28
  • That demo includes compilations of Jade templates. I found it was simple to set it up so jade templates compile into native JS functions as they are saved (during development), which means client script is lightning fast. – Steve Potter Oct 23 '12 at 17:02
5

An in-memory string is the absolute fastest thing you can do, so comparing against it is not very meaningful. A template is never going to be as fast as string concat. Setting to production mode is the most important thing you can do performance wise.

Harry
  • 52,711
  • 71
  • 177
  • 261
  • 4
    I was wondering why it wasn't going as quickly as I liked, and then I realised I hadn't stored my NODE_ENV in .bash_profile. It's crazy the increase in performance that is earnt from setting `export NODE_ENV=production`, on Jade templates and many other Expressy tings. – Matt Fletcher Aug 24 '14 at 18:53
5

(Adding this extra bit of information since this seems to be one of the first search engine hits when looking for "express jade performance")

I had the same issue with a nodejs production application. The problem is that jade runs by default on development mode which is not what you want for production, since this will recompile all templates again and again, wasting cpu and memory.

The solution is to run your app with: NODE_ENV=production node app.js, this will prevent jade recompiling cycle, and perhaps trigger some other express perf improvements.

Note that this doesn't make jade faster, it just prevents it from doing unnecessary work and killing your CPU.

Pablo Fernandez
  • 103,170
  • 56
  • 192
  • 232
  • This actually makes a significant difference. It runs way faster in prodcution mode. – Marc Feb 12 '18 at 18:11
  • is there a way to set "production" mode but in my staging environment has NODE_ENV = test. Is there still a way to override to production settings? – Matt Kim Feb 14 '18 at 19:25