Replies: 3 comments 1 reply
-
The
|
Beta Was this translation helpful? Give feedback.
-
That 'Speeding Up Template Rendering' section mentions that [only] single arguments of type String/Symbol get optimized. A single argument of type Hash doesn't get optimized. The single argument type gets in fact checked in the _cached_template_method method. In other words, the optimized code:
Becomes the unoptimized code:
So, calling the render method with a single argument of type Hash, which is what calling the view method with a block results into, triggers its no-optimization route. |
Beta Was this translation helpful? Give feedback.
-
Actually, I haven't done any benchmarks, but for my simple use case of the view method I think I could override it to something like:
Anyway, thanks again for the good work. |
Beta Was this translation helpful? Give feedback.
-
Hello, I'm the same guy from #262 (Allowing the view method to accept a block).
As I usually arrive on this site by following some link from a search engine,
which often leads to some issue discussions, I wrongly assumed that
the issues section was the only way to communicate something.
Anyway, thanks to you, I now know about the dedicated discussions section.
In general, when I'm not losing anything significant, I like to make my code DRY.
So, when I use templates, I try to apply the DRY rule by picking the appropriate
approache from the following 4 approaches to making dynamic templates:
Helper methods
Template locals
Calling yield
But after looking into how the render plugin works, it looks like, performance wise,
it's best to use either instance variables or helper methods instead of using locals,
which in turn seems better than yield-ing.
If this is true, maybe it could be mentioned somewhere in the docs.
Back to the #262 feature request,
I mentioned there that I'd like to be able to replace:
with:
Then some hours later a commit (which I'm really thankful for)
that implemented this feature appeared.
But, again after looking into how the render plugin works, it seems like when
the view method calls the render_template method, it always does so by passing
a hash as the only argument which effectively skips the 2 potential optimizations
otherwise gained from directly using the render method.
If this is also true, maybe it could be mentioned somewhere in the docs too.
What do you think?
Is the default use of a layout template the only practical difference between
the render and the view methods?
Beta Was this translation helpful? Give feedback.
All reactions