aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/rack_cache_test.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2019-02-05 15:07:55 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2019-02-05 15:24:21 -0800
commit24b068bea13e8f91397b3440494f0a5326f80882 (patch)
tree8aa1cd24df9b05ae02322020a919066725af996f /actionpack/test/dispatch/rack_cache_test.rb
parent0fa0107d2d87f751c6768fa8a0991149134de2df (diff)
downloadrails-24b068bea13e8f91397b3440494f0a5326f80882.tar.gz
rails-24b068bea13e8f91397b3440494f0a5326f80882.tar.bz2
rails-24b068bea13e8f91397b3440494f0a5326f80882.zip
Speed up partial rendering by caching "variable" calculation
This commit speeds up rendering partials by caching the variable name calculation on the template. The variable name is based on the "virtual path" used for looking up the template. The same virtual path information lives on the template, so we can just ask the cached template object for the variable. This benchmark takes a couple files, so I'll cat them below: ``` [aaron@TC ~/g/r/actionview (speed-up-partials)]$ cat render_benchmark.rb require "benchmark/ips" require "action_view" require "action_pack" require "action_controller" class TestController < ActionController::Base end TestController.view_paths = [File.expand_path("test/benchmarks")] controller_view = TestController.new.view_context result = Benchmark.ips do |x| x.report("render") do controller_view.render("many_partials") end end [aaron@TC ~/g/r/actionview (speed-up-partials)]$ cat test/benchmarks/test/_many_partials.html.erb Looping: <ul> <% 100.times do |i| %> <%= render partial: "list_item", locals: { i: i } %> <% end %> </ul> [aaron@TC ~/g/r/actionview (speed-up-partials)]$ cat test/benchmarks/test/_list_item.html.erb <li>Number: <%= i %></li> ``` Benchmark results (master): ``` [aaron@TC ~/g/r/actionview (master)]$ be ruby render_benchmark.rb Warming up -------------------------------------- render 41.000 i/100ms Calculating ------------------------------------- render 424.269 (± 3.5%) i/s - 2.132k in 5.031455s ``` Benchmark results (this branch): ``` [aaron@TC ~/g/r/actionview (speed-up-partials)]$ be ruby render_benchmark.rb Warming up -------------------------------------- render 50.000 i/100ms Calculating ------------------------------------- render 521.862 (± 3.8%) i/s - 2.650k in 5.085885s ```
Diffstat (limited to 'actionpack/test/dispatch/rack_cache_test.rb')
0 files changed, 0 insertions, 0 deletions