3 ms·
It's always annoyed me how slow Ruby/Rails is at rendering views and partials. I don't know why, but some of our small partials that don't do any network calls
by joevandyk 14y ago
It's always annoyed me how slow Ruby/Rails is at rendering views and partials. I don't know why, but some of our small partials that don't do any network calls take a long time to render. Profiling them doesn't really seem to help. Possibly it's GC related.
If template rendering was faster, it wouldn't be as necessary to worry about caching, which brings tons of headaches and complexity.
- steveklabnik 14y agoIf you're rendering a bunch of partials in a loop, you should try rendering it as a collection instead; it's significantly faster.
- netghost 14y agoI know I should just go read the code, but any insight into what the difference is?
- steveklabnik 14y agoRather than all the setup and teardown work that's done for every single partial, that work can be done once for the entire collection.
- netghost 14y agoThanks Steve, that makes perfect sense.
- pjungwir 14y agoI remember looking into a similar problem once and seeing something like: rendered "foo" 2ms rendered "foo" 2ms rendered "foo" 1ms rendered "foo" 4ms rendered "foo" 175ms rendered "foo" 2ms Assuming a really simple partial (and no swapping or run queue), that looks suspiciously like a GC problem.
- taf2 14y agothere is disk i/o involved in rendering each partial every request in development and at least once in production...
- jeltz 14y agoI have not looked into it in detail but when I worked on a project using Ramaze and Erubis I had no problems so I am pretty sure the slowdown is somewhere in rails. No idea where though. It is probably partially GC related, but I have no idea why Rails need to create many objects when rendering a template.