Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering haml partials takes a long time... why?

My Rails 3.0 app on ruby 1.8.7 contains Haml 3.1.3. Most of the views are haml templates, it takes about 0.5-5ms to render them on my machine in production mode.

Having said that, a few partials take much longer. 300ms to 900ms for 30-60 lines of haml. It must be something in the way how I use it, but how could I debug what's wrong? The benchmarks are consistent and reproducible.

I'm not sure about possible sources of the error:

  • deep partial nesting? (3-5 levels)
  • deep haml nesting? (4-8 levels)
  • use of block helpers?
  • lots of translations?
  • using haml with formtastic 2.0?
  • using form builders for nested forms?

Any help is appreciated.

like image 868
datenimperator Avatar asked Nov 05 '22 11:11

datenimperator


1 Answers

It turned out to be a number of things inside Formtastic 2.0:

  • Lots of object lookups, uncached
  • Lots of translations, uncached
  • Use of try…rescue blocks which slowed it down tremendously

Fixes have been added to Formtastic 2.1 and up, making it a lot faster. Kudos to Sascha Konietzke for providing patches.

like image 140
datenimperator Avatar answered Nov 09 '22 15:11

datenimperator