In response to this experiment from a couple of years ago.
I often wonder about when it’s appropriate to use helpers or partials in Rails. There’s the ideological question (answered well in this post).
However, there’s also a performance question. You can’t help but feel that helpers are better when you see things like this in your logs:
Rendered selections/_list_item.html.erb (11.5ms) Rendered selections/_frame.html.erb (17.0ms) Rendered selections/_list_item.html.erb (0.3ms) Rendered selections/_frame.html.erb (2.2ms) Rendered selections/_list_item.html.erb (0.2ms) Rendered selections/_frame.html.erb (2.0ms) ...and so on when you are rendering a lot of partials
However, this is development. Things are different on production. For instance if you follow Ben’s example and run tests on development, you might see (here’s the code):
ab -n 100 -c 5 -r http://helpers-vs-partials.dev/test/#{METHOD}
When `METHOD` is (result is req/s, higher is better):
partial: 2.20 helper: 5.93 partial_collection: 28.52
Which might lead you to make some kind of conclusions (probably quite similar to the ones Ben reached).
But, if you push the app up to a production server (heroku makes this super easy.. thanks guys!). You might see something more like:
partial:0.91 helper: 0.98 partial_collection: 1.01
Certainly not worth worrying about. QED.
I agree with the notion that the uedrrscone prefix for partials is kind of sucky (although I’ve gotten used to it) but I disagree with the suggestion to shift it to the last part of the filename (e.g. perb). For me it just feels like it voids the purpose (well, to a degree atleast) of using the .. syntax.To be honest, I think a seperate partials folder (which it looks in automatically) would be a better idea but even that has flaws.