Ruby on Rails: Why does calling partial in my views take a lot of time to render?

For example, I call three partial files in the recipes / _cuisines.html.erb file:

  <%= render "recipes/cuisines/denmark.html %>
  <%= render "recipes/cuisines/spain.html %>
  <%= render "recipes/cuisines/italy.html %>

There is nothing more in this file. Particles are just static content with no collections. This is what I get from my magazines:

  Rendered recipes/cuisines/_denmark.html.erb (4.6ms) [cache miss]
  Rendered recipes/cuisines/_spain.html.erb (2.3ms) [cache miss]
  Rendered recipes/cuisines/_italy.html.erb (5.3ms) [cache miss]
  Rendered recipes/_cuisines.html.erb (161.5ms) [cache miss]

If I remove one of the partial, I get something like:

  Rendered recipes/cuisines/_denmark.html.erb (4.6ms) [cache miss]
  Rendered recipes/cuisines/_spain.html.erb (2.3ms) [cache miss]
  Rendered recipes/_cuisines.html.erb (101.7ms) [cache miss]

Removing another particle:

  Rendered recipes/cuisines/_denmark.html.erb (4.6ms) [cache miss]
  Rendered recipes/_cuisines.html.erb (50.5ms) [cache miss]

Removing all partial, I get something like this:

  Rendered recipes/_cuisines.html.erb (0.9ms) [cache miss]

It seems that partial partiality requires extraordinary time, even if partial partial is very small. Do you know what reasons and what I can do to name partial operations faster? Is it recommended not to name partial at all?

(I am using Rails 5.1.1 and ruby ​​2.5.0dev)

+4
1

, . , config.cache_classes, false true , rails.

config.cache_classes , . false true .

config.action_view.cache_template_loading , . config.cache_classes.

test production, .

+2

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


All Articles