S
S
Splite2016-02-26 15:01:12
Ruby on Rails
Splite, 2016-02-26 15:01:12

How to optimize haml render speed?

Hello! The page on haml is rendered almost 200ms. For comparison, queries to the database are completed in 6ms.
I tried to rewrite to slim, the result became smaller, but not much. Through experiments, I found out that most of the time is occupied by an each-loop through elements from the database (ActiveRecord_Relation ). There are exactly 50 of these elements on one page.
Even if only the basic information about each record is displayed inside each, the cycle is very long
. Is this a normal situation? How to speed up page rendering?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
SidhArt, 2016-02-26
@SidhArt

N+1, pagination, caching. Caching the greatest gain.

A
Anton Radushevsky, 2016-02-26
@doromones

apidock.com/rails/ActiveRecord/QueryMethods/includes
Try this

R
Roman Mirilaczvili, 2016-02-26
@2ord

You can, as Anton Radushevsky wrote , but it's better to get all the data in advance in the controller (50 pieces), and only insert them in the view. Then there will be no DB call costs inside the HAML template loop.

A
Anton Misyagin, 2016-03-04
@sunnmas

Maybe this is the point?)) How to speed up the rendering of nested simple_fields_for fields?

S
Splite, 2016-03-11
@Splite

I made caching of a part of the template with a table, it became an order of magnitude faster, of course, but still not happy.
I really like RoR, writing on it is pure pleasure.
But is it normal for a table of 50 elements to render in 200ms? Is he really that slow? And this despite the fact that requests to the database take less than 5ms. The cycle definitely does not create additional requests

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question