1. 03 8月, 2015 14 次提交
  2. 02 8月, 2015 6 次提交
    • B
      Save a string allocation inside loop · d531edc8
      Benjamin Quorning 提交于
      In the `tag_options` method, strings are continuously added to the
      `output` string. Previously, we concatenated two strings and added the
      generated string to `output`. By adding each of the strings to
      `output`, one after the other, we will save the allocation of that
      concatenated string.
      
      Benchmark:
      
          require 'benchmark/ips'
      
          sep = " ".freeze
      
          Benchmark.ips do |x|
            x.report("string +") {
              output = ""
              output << sep + "foo"
            }
            x.report("string <<") {
              output = ""
              output << sep
              output << "foo"
            }
            x.compare!
          end
      
      Results (Ruby 2.2.2):
      
          Calculating -------------------------------------
                      string +    88.086k i/100ms
                     string <<    94.287k i/100ms
          -------------------------------------------------
                      string +      2.407M (± 5.8%) i/s -     12.068M
                     string <<      2.591M (± 7.0%) i/s -     12.917M
      
          Comparison:
                     string <<:  2591482.4 i/s
                      string +:  2406883.7 i/s - 1.08x slower
      d531edc8
    • B
      Use #start_with? and #[] for speed · 113f8a6c
      Benjamin Quorning 提交于
      While the readability may be slightly worse, the speed improvement is
      significant: Twice as fast when there's no leading "/" to remove, and
      over 4 times as fast when there is a leading "/".
      
      Benchmark:
      
          require 'benchmark/ips'
      
          def match(controller)
            if controller
              if m = controller.match(/\A\/(?<controller_without_leading_slash>.*)/)
                m[:controller_without_leading_slash]
              else
                controller
              end
            end
          end
      
          def start_with(controller)
            if controller
              if controller.start_with?('/'.freeze)
                controller[1..-1]
              else
                controller
              end
            end
          end
      
          Benchmark.ips do |x|
            x.report("match") { match("no_leading_slash") }
            x.report("start_with") { start_with("no_leading_slash") }
      
            x.compare!
          end
      
          Benchmark.ips do |x|
            x.report("match") { match("/a_leading_slash") }
            x.report("start_with") { start_with("/a_leading_slash") }
      
            x.compare!
          end
      
      Result (Ruby 2.2.2):
      
          Calculating -------------------------------------
                         match    70.324k i/100ms
                    start_with   111.264k i/100ms
          -------------------------------------------------
                         match      1.468M (± 7.1%) i/s -      7.314M
                    start_with      3.787M (± 3.5%) i/s -     18.915M
      
          Comparison:
                    start_with:  3787389.4 i/s
                         match:  1467636.4 i/s - 2.58x slower
      
          Calculating -------------------------------------
                         match    36.694k i/100ms
                    start_with    86.071k i/100ms
          -------------------------------------------------
                         match    532.795k (± 4.7%) i/s -      2.679M
                    start_with      2.518M (± 5.8%) i/s -     12.566M
      
          Comparison:
                    start_with:  2518366.8 i/s
                         match:   532794.5 i/s - 4.73x slower
      113f8a6c
    • A
      Merge pull request #21097 from y-yagi/fix_button_to_example · 13beb92a
      Arun Agrawal 提交于
      correct example of button_tag [ci skip]
      13beb92a
    • Y
      correct example of button_tag [ci skip] · ac65bff3
      yuuji.yaginuma 提交于
      wrapper div has been removed in cbb91745
      ac65bff3
    • S
      Fix test failures caused by #20884 · 722abe17
      Sean Griffin 提交于
      PostgreSQL is strict about the usage of `DISTINCT` and `ORDER BY`, which
      one of the tests demonstrated. The order clause is never going to be
      relevant in the query we're performing, so let's just remove it
      entirely.
      722abe17
    • S
      Merge pull request #20884 · cc109111
      Sean Griffin 提交于
      Add #cache_key to ActiveRecord::Relation.
      cc109111
  3. 01 8月, 2015 5 次提交
  4. 31 7月, 2015 15 次提交
    • Y
      Merge pull request #21063 from cmisenas/fix-guides-warning-env · d1cdf52d
      Yves Senn 提交于
      Fix WARNINGS flag inside guides/Rakefile
      d1cdf52d
    • Y
      Merge pull request #20992 from JuanitoFatas/fix/bin-setup-script · 5ca385cb
      Yves Senn 提交于
      Don't fail when checking dependencies in bin/setup script
      5ca385cb
    • R
      Merge pull request #21075 from byroot/not-empty-vs-any · f8e81d41
      Rafael Mendonça França 提交于
      Array#any? is slower and not the inverse of Array#empty?
      f8e81d41
    • J
      Array#any? is slower and not the inverse of Array#empty? · 32133db7
      Jean Boussier 提交于
      ```
      empty_array = []
      small_array = [1] * 30
      bigger_array = [1] * 300
      
      Benchmark.ips do |x|
        x.report('empty !empty?') { !empty_array.empty? }
        x.report('small !empty?') { !small_array.empty? }
        x.report('bigger !empty?') { !bigger_array.empty? }
      
        x.report('empty any?') { empty_array.any? }
        x.report('small any?') { small_array.any? }
        x.report('bigger any?') { bigger_array.any? }
      end
      ```
      
      ```
      Calculating -------------------------------------
             empty !empty?   132.059k i/100ms
             small !empty?   133.974k i/100ms
            bigger !empty?   133.848k i/100ms
                empty any?   106.924k i/100ms
                small any?    85.525k i/100ms
               bigger any?    86.663k i/100ms
      -------------------------------------------------
             empty !empty?      8.522M (± 7.9%) i/s -     42.391M
             small !empty?      8.501M (± 8.5%) i/s -     42.202M
            bigger !empty?      8.434M (± 8.6%) i/s -     41.894M
                empty any?      4.161M (± 8.3%) i/s -     20.743M
                small any?      2.654M (± 5.2%) i/s -     13.256M
               bigger any?      2.642M (± 6.4%) i/s -     13.173M
      ```
      
      Ref: https://github.com/rails/rails/pull/21057#discussion_r35902468
      32133db7
    • R
      Merge pull request #21057 from schneems/schneems/journey-formatter-objects · 5373bf22
      Richard Schneeman 提交于
      Beyond Ludicrous Speed
      5373bf22
    • S
      Use delete_if instead of each; delete(key) · 22f59240
      schneems 提交于
      It is slightly faster:
      
      ```
      Calculating -------------------------------------
              each; delete    35.166k i/100ms
                 delete_if    36.416k i/100ms
      -------------------------------------------------
              each; delete    478.026k (± 8.5%) i/s -      2.391M
                 delete_if    485.123k (± 7.9%) i/s -      2.440M
      ```
      22f59240
    • S
      Remove (another) array allocation · 61dae882
      schneems 提交于
      We don't always need an array when generating a url with the formatter. We can be lazy about allocating the `missing_keys` array. This saves us:
      
      35,606 bytes and 889 objects per request
      61dae882
    • S
      Remove array allocation · 4d2ccc11
      schneems 提交于
      THe only reason we were allocating an array is to get the "missing_keys" variable in scope of the error message generator. Guess what? Arrays kinda take up a lot of memory, so by replacing that with a nil, we save:
      
      35,303 bytes and 886 objects per request
      4d2ccc11
    • S
      zOMG 37 objects saved · 005541b8
      schneems 提交于
      005541b8
    • S
      Don't allocate array when not necessary · 1f831fef
      schneems 提交于
      In the `tag_options` method an array is used to build up elements, then `Array#*` (which is an alias for `Array#join` is called to turn the array into a string. Instead of allocating an array to build a string, we can build the string we want from the beginning.
      
      Saved: 121,743 bytes 893 objects
      1f831fef
    • S
      String#freeze optimizations · 0d7a714d
      schneems 提交于
      0d7a714d
    • S
      Decrease allocations in transliterate · 57ba9cbc
      schneems 提交于
      We can save a few objects by freezing the `replacement` string. We save a few more by down-casing the string in memory instead of allocating a new one. We save far more objects by checking for the default separator `"-"`, and using pre-generated regular expressions.
      
      We will save 209,231 bytes and 1,322 objects.
      57ba9cbc
    • S
      Avoid hash duplication by skipping mutation · 1993e2cc
      schneems 提交于
      If we don't mutate the `recall` hash, then there's no reason to duplicate it. While this change doesn't get rid of that many objects, each hash object it gets rid of was massive.
      
      Saves 888 string objects per request, 206,013 bytes (thats 0.2 mb which is kinda a lot).
      1993e2cc
    • S
      Only allocate new string when needed · 3fb9e802
      schneems 提交于
      Instead of calling `sub` on every link_to call for controller, we can detect when the string __needs__ to be allocated and only then create a new string (without the leading slash), otherwise, use the string that is given to us.
      
      Saves 888 string objects per request, 35,524 bytes.
      3fb9e802
    • S
      Freeze a string in comparator · 045cdd3a
      schneems 提交于
      Saves 888 string objects per request.
      045cdd3a