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

John Wells picture John Wells · Sep 18, 2008 · Viewed 15.9k times · Source

I have been playing with Haml recently and really like the way the resulting code looks to me...the developer. I'm also not too worried about a designer being able to consume or change it...we're a small team.

That said, beginning work on a project we believe will generate quite a bit of traffic (who doesn't?). I'm concerned that there are things I just don't know about haml. Is there anything erb can do that haml can't? Does haml have a negative effect as a project grows? Are there other things that should be considered?

And finally...how does Haml compare speedwise to erubis? I see that it supposedly beats erb and eruby now...

Thanks!

Answer

outcassed picture outcassed · Sep 19, 2008

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.