This PR optimizes ViewModel#render in two cases / ways.
First case 'explizit render': Before this PR #render calls caller and give the result to normalize_options, which don't work with the caller when a explizit view name is used.
The PR makes this case ~25% faster
Second case 'implizit render': Before this PR the complete caller stack would be read, but we only need the last 2 segments. By only reading the 2 last segments, the caller call is faster and don't produce big arrays, which optimize the memory footprint.
The PR makes this case ~20% faster
Note: all test are based on this Cell, Model and View:
model = "test"
class TestCell < Cell::ViewModel
def index
render
end
def index_explizit
render "index"
end
end
<%= model %>
I also remove the TODO: speedup by not doing state_for_implicit_render. comment. I think this code don't need to optimize anymore, this is now only ~5% slower as the explizit way.
This PR optimizes
ViewModel#render
in two cases / ways.First case 'explizit render': Before this PR
#render
callscaller
and give the result tonormalize_options
, which don't work with thecaller
when a explizit view name is used. The PR makes this case ~25% fasterSecond case 'implizit render': Before this PR the complete
caller
stack would be read, but we only need the last 2 segments. By only reading the 2 last segments, thecaller
call is faster and don't produce big arrays, which optimize the memory footprint. The PR makes this case ~20% fasterNote: all test are based on this Cell, Model and View:
I also remove the
TODO: speedup by not doing state_for_implicit_render.
comment. I think this code don't need to optimize anymore, this is now only ~5% slower as the explizit way.