1. 16 3月, 2019 1 次提交
    • S
      Rename `ActionView::Base#run` to `#_run` · 47fea39e
      Seb Jacobs 提交于
      There was a recent change by @tenderlove to Action view which introduced
      `ActionView::Base#run` [1].
      
      We ran into an issue with our application because one of the core
      concepts in our domain model is a `Run` which is exposed in most of our
      views as a helper method, which now conflicts with this new method.
      
      Although this is a public method it is not really meant to be part of
      the public API.
      
      In order to discourage public use of this method and to reduce the
      chances of this method conflicting with helper methods we can prefix
      this method with an underscore, renaming this method to `_run`.
      
      [1] https://github.com/rails/rails/commit/c740ebdaf5
      47fea39e
  2. 27 2月, 2019 1 次提交
  3. 26 2月, 2019 12 次提交
  4. 23 2月, 2019 1 次提交
    • A
      Add a finalizer to inline templates · 52eafbd7
      Aaron Patterson 提交于
      This commit adds a finalizer just to inline templates.  We can't cache
      compilation of inline templates because it's possible that people could
      have render calls that look like this:
      
      ```ruby
      loop do
        render inline: "#{rand}"
      end
      ```
      
      and we would cache every one of these different inline templates.  That
      would cause a memory leak.  OTOH, we don't need finalizers on regular
      templates because we can cache, control, and detect changes to the
      template source.
      
      Fixes: #35372
      52eafbd7
  5. 16 2月, 2019 1 次提交
    • A
      Pass the template format to the digestor · 1581cab9
      Aaron Patterson 提交于
      This commit passes the template format to the digestor in order to come
      up with a key.  Before this commit, the digestor would depend on the
      side effect of the template renderer setting the rendered_format on the
      lookup context.  I would like to remove that mutation, so I've changed
      this to pass the template format in to the digestor.
      
      I've introduced a new instance variable that will be alive during a
      template render.  When the template is being rendered, it pushes the
      current template on to a stack, setting `@current_template` to the
      template currently being rendered.  When the cache helper asks the
      digestor for a key, it uses the format of the template currently on the
      stack.
      1581cab9
  6. 07 2月, 2019 2 次提交
  7. 06 2月, 2019 1 次提交
    • A
      Speed up partial rendering by caching "variable" calculation · 24b068be
      Aaron Patterson 提交于
      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
      ```
      24b068be
  8. 02 2月, 2019 2 次提交
  9. 01 2月, 2019 1 次提交
  10. 19 1月, 2019 1 次提交
    • A
      Ask the view for its method container · 0f081611
      Aaron Patterson 提交于
      Rather than doing is_a? checks, ask the view object for its compiled
      method container.  This gives us the power to replace the method
      container depending on the instance of the view.
      0f081611
  11. 17 1月, 2019 3 次提交
  12. 04 10月, 2018 1 次提交
  13. 02 10月, 2018 1 次提交
  14. 01 10月, 2018 2 次提交
  15. 29 9月, 2018 1 次提交
    • Y
      Add `Style/RedundantFreeze` to remove redudant `.freeze` · aa3dcabd
      Yasuo Honda 提交于
      Since Rails 6.0 will support Ruby 2.4.1 or higher
      `# frozen_string_literal: true` magic comment is enough to make string object frozen.
      This magic comment is enabled by `Style/FrozenStringLiteralComment` cop.
      
      * Exclude these files not to auto correct false positive `Regexp#freeze`
       - 'actionpack/lib/action_dispatch/journey/router/utils.rb'
       - 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb'
      
      It has been fixed by https://github.com/rubocop-hq/rubocop/pull/6333
      Once the newer version of RuboCop released and available at Code Climate these exclude entries should be removed.
      
      * Replace `String#freeze` with `String#-@` manually if explicit frozen string objects are required
      
       - 'actionpack/test/controller/test_case_test.rb'
       - 'activemodel/test/cases/type/string_test.rb'
       - 'activesupport/lib/active_support/core_ext/string/strip.rb'
       - 'activesupport/test/core_ext/string_ext_test.rb'
       - 'railties/test/generators/actions_test.rb'
      aa3dcabd
  16. 23 9月, 2018 1 次提交
    • Y
      Enable `Performance/UnfreezeString` cop · 1b86d901
      yuuji.yaginuma 提交于
      In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`.
      
      ```ruby
      # frozen_string_literal: true
      
      require "bundler/inline"
      
      gemfile(true) do
        source "https://rubygems.org"
      
        gem "benchmark-ips"
      end
      
      Benchmark.ips do |x|
        x.report('+@') { +"" }
        x.report('dup') { "".dup }
        x.compare!
      end
      ```
      
      ```
      $ ruby -v benchmark.rb
      ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
      Warming up --------------------------------------
                        +@   282.289k i/100ms
                       dup   187.638k i/100ms
      Calculating -------------------------------------
                        +@      6.775M (± 3.6%) i/s -     33.875M in   5.006253s
                       dup      3.320M (± 2.2%) i/s -     16.700M in   5.032125s
      
      Comparison:
                        +@:  6775299.3 i/s
                       dup:  3320400.7 i/s - 2.04x  slower
      
      ```
      1b86d901
  17. 03 4月, 2018 2 次提交
    • B
      Use `:default` option in order to set default value of `finalize_compiled_template_methods` · e6f3882c
      bogdanvlviv 提交于
      Since we introduced default option for `class_attribute` and
      `mattr_accessor` family of methods and changed all occurrences of setting
      default values by using of `:default` option I think it would be fine to use
      `:default` option in order to set default value of `finalize_compiled_template_methods`
      since it expresses itself very well.
      
      Related to #29294, #32418
      e6f3882c
    • S
      Add `action_view.finalize_compiled_template_methods` config option · eede8d81
      Simon Coffey 提交于
      ActionView::Template instances compile their source to methods on the
      ActionView::CompiledTemplates module. To prevent leaks in development
      mode, where templates can frequently change, a finalizer is added that
      undefines these methods[1] when the templates are garbage-collected.
      
      This is undesirable in the test environment, however, as templates don't
      change during the life of the test. Moreover, the cost of undefining a
      method is proportional to the number of descendants a class or module
      has, since the method cache must be cleared for all descendant classes.
      
      As ActionView::CompiledTemplates is mixed into every
      ActionView::TestCase (or in RSpec suites, every view spec example
      group), it can end up with a very large number of descendants, and
      undefining its methods can become very expensive.
      
      In large test suites, this results in a long delay at the end of the
      test suite as all template finalizers are run, only for the process to
      then exit.
      
      To avoid this unnecessary cost, this change adds a config option,
      `action_view.finalize_compiled_template_methods`, defaulting to true,
      and sets it to false in the test environment only.
      
      [1] https://github.com/rails/rails/blob/09b2348f7fc8d4e7191e70e06608c5909067e2aa/actionview/lib/action_view/template.rb#L118-L126
      eede8d81
  18. 02 9月, 2017 1 次提交
  19. 01 9月, 2017 1 次提交
  20. 11 7月, 2017 1 次提交
  21. 07 7月, 2017 1 次提交
  22. 02 7月, 2017 1 次提交
  23. 01 7月, 2017 1 次提交