Benchmarks

bminer edited this page Mar 7, 2013 · 8 revisions

Benchmarks

Overview

The Blade parser/compiler is a bit slow. That's probably okay because Blade makes it easy to cache compiled views. If you use Blade with Express, for example, Express will automatically cache compiled views when running with NODE_ENV === "production".

The most crucial part of Blade's performance lies with the performance of compiled templates and the performance of the Blade runtime. I'm pleased to say that the runtime is pretty darn fast. On my computer, I can render a reasonably complex template with file includes in less than 1ms. This test was performed on Google Chrome v18 on Windows 7 on a two-year-old laptop (i7 processor). I got around 12,000 renders per second.

Blade Performance Summary on a "decent" computer:

  • Minified template render time: ~1,000 - 2,000 renders per second (pretty darn good)
  • Minified template compile time (no caching): ~250 - 300 small templates per second. This is around 4,000 lines of Blade per second... like I said, quite slow.
  • Minified template compile time (with caching) ~30,000+ templates per second (yay caching!)

You can test the performance of Blade on your machine by running the test/benchmark.js file.

Output of benchmark.js on EC2 m1.medium instance (Ubuntu 12.04, Node 0.6.17, Blade 1.3.3):

Blade performance:
------------------
Blade test suite statistics:
        Files: 24
        Total number of lines: 303

Parse the entire test suite 40 times: 1572ms
Compile (cache off, minify on) the entire test suite 40 times: 2583ms
Render (cache off, minify on) the entire test suite 40 times: 3212ms
Compile and cache the entire test suite 1 times: 72ms
Compile (cache on, minify on) the entire test suite 1000 times: 220ms
Render (cache on, minify on) the entire test suite 1000 times: 1963ms

Output of benchmark.js on EC2 m1.medium instance (Ubuntu 12.04, Node 0.8.18, Blade 3.0.0rc3):

Blade performance:
------------------
Blade test suite statistics:
        Files: 35
        Total number of lines: 487

Parse the entire test suite 40 times: 4503ms
Compile (cache off, minify on) the entire test suite 40 times: 5081ms
Render (cache off, minify on) the entire test suite 40 times: 7348ms
Compile and cache the entire test suite 1 times: 116ms
Compile (cache on, minify on) the entire test suite 1000 times: 10265ms
Render (cache on, minify on) the entire test suite 1000 times: 23937ms

Possible Improvements

To improve the compiler's speed...

  • Focus on the parser first. Right now, parsing a string of Blade accounts for about 80% of the work that needs to be done to compile a Blade template. Since, Blade's parser is automatically generated by PEG.js, there is not much we can do here except tweak the grammar, build a new parser from scratch, or improve the PEG.js library.
  • Clean up and improve lib/compiler.js
  • Possibly do more caching

To improve the runtime speed...

  • Clean up lib/runtime.js to make it run a bit faster
  • Analyze a few compiled templates to see if easy improvements can be made
  • Possibly get rid of with() {} blocks, if possible. This might improve variable lookup times.

Performance Results from Others

If you are using Blade, and you want to post your benchmark results, please add them below!

your benchmench test results go here!