trailblazer / cells

View components for Ruby and Rails.
https://trailblazer.to/2.1/docs/cells.html
3.07k stars 236 forks source link

Optimize render #331

Closed timoschilling closed 9 years ago

timoschilling commented 9 years ago

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.