Partial rendering of haml takes a lot of time ... why?

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

Having said that, some partial parts take much longer. From 300 ms to 900 ms for 30-60 haml lines. It should be something in the way I use it, but how can I debug what is wrong? Benchmarks are consistent and reproducible.

I am not sure about the possible sources of the error:

  • deep partial investment? (3-5 levels)
  • deep haml enclosure? (4-8 levels)
  • using block helpers?
  • many translations?
  • Using haml with formtastic 2.0?
  • using form builders for nested forms?

Any help is appreciated.

+4
source share
4 answers

There were a few things in Formtastic 2.0:

  • Search for inactive objects
  • Many translations, no access
  • Using try ... rescue blocks that slowed it down significantly.

Corrections added in Formtastic 2.1 and higher, which significantly speeds up the work. Kudos Sascha Konietzke for providing patches.

0
source

A later way to fix this is Hamlit , a high-performance implementation of Haml with some design limitations for performance. It requires 8.24 times faster.

Also, not Haml-specific, but look at the multi-photographic stone for listings.

+1
source

Most likely, this is garbage collection. See the following posts:

http://www.williambharding.com/blog/uncategorized/rails-3-performance-abysmal-to-good-to-great/comment-page-1/

http://bibwild.wordpress.com/2011/06/28/rails3-unbearably-slow-view-rendering-use-ree-with-gc-tuning/

If you are using REE 1.8.7 (which also fixes a memory leak, so you should be), you can configure your GC settings . I just did this last week and our response time has decreased by 50%.

0
source

Insert .bashrc :

 export RUBY_GC_HEAP_INIT_SLOTS=1000000 export RUBY_HEAP_SLOTS_INCREMENT=500000 export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1 export RUBY_GC_MALLOC_LIMIT=50000000 

Reboot source and server

 $> source ~/.bashrc $> rails s 

Depending on your problem, this may speed up the rendering of your partitions (in my case, the average rendering time increased by x3 faster).

0
source

Source: https://habr.com/ru/post/1381327/


All Articles