Rails: slow partial rendering when cache_classes is false
I am upgrading my Rails 3.2 application to version 5. The first thing I do is upgrade to version 4 and make all tests still pass.
One thing I noticed is that my application is very slow right now in development mode. Some requests take 1500ms when they take less than 50ms in 3.2.
After some debugging, I found that if I enable the cache_classes configuration in version 4, I get similar performance to the one I used in version 3.2 with cache_classes disabled.
Rails 4.2.9 (config.cache_classes = false)
(previous render messages intentionally removed )
Rendered application/_row.html.erb (91.2ms)
Rendered application/_row.html.erb (104.1ms)
Rendered application/_row.html.erb (103.9ms)
Completed 200 OK in 1617ms (Views: 1599.0ms | ActiveRecord: 8.3ms)
Rails 4.2.9 (config.cache_classes = true)
(previous render messages intentionally removed )
Rendered application/_row.html.erb (2.3ms)
Rendered application/_row.html.erb (2.5ms)
Rendered application/_row.html.erb (2.0ms)
Completed 200 OK in 59ms (Views: 41.8ms | ActiveRecord: 7.7ms
From what I was able to check, when config.cache_classes = false, the partials and classes are no longer cached by Rails. Even in the same query as before, in 3.2.
I also checked config.reload_classes_only_on_change which seemed appropriate and it set it to true.
Is there something else that I have to check / change to get a similar one I had in 3.2 with cache_classes disabled? Or is it a regression in Rails that can't be fixed?
Unfortunately, developing with cache_classes enabled is not safe.
Note 1: I created empty rails 4.2.9 and was able to reproduce this issue by creating many partitions and enabling / disabling cache_classes.
Note 2: The same problem occurs in Rails 5. I am focusing on Rails 4 because the one I am currently working with.
source to share
No one has answered this question yet
Check out similar questions: