Closed bjeanes closed 3 years ago
Thanks for the report. Yes, I would definitely like to add a performance patch for this for Rails 5.x. I'll try to get more familiar with the related Action View code, and see if it's possible to add a safe patch. Using respond_to
might be possible, thanks for the tip.
Does this problem occur when rendering any template in Rails 5 (in other controllers)? Or just with manually created controller instances used in rodauth-rails?
Good question. It was my colleague @chendo who did the benchmarking, so hopefully he can weigh in on that, but it was my understanding from his internal PR that it was just Rodauth. He only added that _render_template
call in our RodauthController
It was specifically just Rodauth. Regular Rails controllers in the same project use globs that look like this: "/app/app/views/controller/action{.en,}{.html,}{}{.raw,.erb,.html,.builder,.ruby,.coffee,.slim,.jbuilder,.haml,}"
That particular controller action has no explicit render
call, so something in Rails would be limiting the extensions to just .html
After some looking, I found out that Action Controller normally limits the template formats for lookup to the ones accepted by the current request (code). This is why classic rendering inside a controller is fast even without using respond_to
.
In rodauth-rails case, template rendering is happening outside of action processing, so this code isn't being executed. I've opened https://github.com/janko/rodauth-rails/pull/52 which should fix this by adding this logic. @chendo Could you verify whether it works for you?
I'm not sure if there is a clear fix that will work for all cases, but I wanted to bring this to your attention.
We've have really slow view loading in certain contexts. The glob that it searches for views ends up compiling to:
I'm supposing we don't have this problem elsewhere because Rails might eliminate options here from information from routing layer, but that's just speculation.
I think somehow incorporating
respond_to { html { } }
around the renders may cut this down significantly.For some members of our team (particularly macOS users where Docker's filesystem access is pretty indirect), these renders can be > 300ms.
We are on Rails 5, so perhaps Rails 6 wouldn't have this problem due to https://github.com/rails/rails/pull/33860
We've worked around this by inserting the following into our rodauth controller: