-
Notifications
You must be signed in to change notification settings - Fork 28
Benchmarks
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.
- 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.
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
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
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.
If you are using Blade, and you want to post your benchmark results, please add them below!
your benchmench test results go here!