Running the risk of being tagged as "too broad", but this is an authentic doubt.
Say I have
@my_model.complex_calculation_result to show in a view.
What are the pros and cons of:
1 - Calculating the value on the controller and send it to the view
Controller:
@result = @my_model.complex_calculation_result # caching the value in the controller
View:
<%= @result %>
2 - Calculating it directly in the view
<%= @my_model.complex_calculation_result %>
I know the last alternative represents less code and I have one less instance variable hanging around.
But are there performance diferences?
Guess 1 - the view already takes more memory to render it all, so the calculation can take longer from inside the view if it is memory expensive.
Any light shed on this and comments will be highly appreciated. :)