Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up partial rendering by caching "variable" calculation #35171

Merged
merged 1 commit into from
Feb 6, 2019

Commits on Feb 5, 2019

  1. 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
    ```
    tenderlove committed Feb 5, 2019
    Configuration menu
    Copy the full SHA
    24b068b View commit details
    Browse the repository at this point in the history