Should I use haml or erb or erubis for potentially high traffic site? Should I use haml or erb or erubis for potentially high traffic site? ruby-on-rails ruby-on-rails

Should I use haml or erb or erubis for potentially high traffic site?


Haml rocks. I haven't seen any recent performance numbers but it is pretty close to erb these days. I think that it might be faster than erb if you turn on ugly mode (which prevents the pretty indentation) We're doing 2.8 million pageviews a day with Haml.

There is a benchmarker checked into the Haml source tree:http://github.com/nex3/haml/tree/master/test

Update November 2009

Nathan (Haml's main developer) published some Haml 2.2 benchmarks on his blog. You can see the exact numbers there but in short:

  • Normal (pretty printing) mode = 2.8 times slower than ERB
  • Ugly mode (no pretty tabs added) = equal to ERB

You can enable ugly mode by placing Haml::Template::options[:ugly] = true in an initializer or environment file. Note that ugly mode isn't really that ugly - the resulting HTML is actually much prettier than ERB - it's just not indented nicely.


If you use Rails, the performance difference between Haml and erubis is negligible: templates get compiled and cached after the first hit, anyway. Combine this with fragment and page caching and you can rest assured that views are not the performance bottleneck of your application.

The question you should be asking yourself is: do you like writing Haml? Does it make you more productive? Then you can decide easier.


I love HAML since it is a good tool for easily writing structured HTML, and generally it is just a joy to use. But it has very little to do with choosing a tool based on the amount of traffic a site might have.

If you are worried about traffic, you should worry about using caching properly. And then you need to apply the principles of general web-application performance - the result is that you will have super snappy responses to page loads. Which is what a high-traffic website really needs.

A couple of presentations that show how to improve website performance can be found here:

And the best place that I know of to learn how to use rails caching properly is: