1. 02 8月, 2015 1 次提交
  2. 01 8月, 2015 5 次提交
  3. 31 7月, 2015 16 次提交
    • 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
    • S
      Avoid calling to_s on nil in journey/formatter · bff61ba2
      schneems 提交于
      When `defaults[key]` in `generate` in the journey formatter is called, it often returns a `nil` when we call `to_s` on a nil, it allocates an empty string. We can skip this check when the default value is nil.
      
      This change buys us 35,431 bytes of memory and 887 fewer objects per request.
      
      Thanks to @matthewd for help with the readability
      bff61ba2
  4. 30 7月, 2015 17 次提交
    • K
      Merge pull request #21071 from hedgesky/remove_yepnope_mention_from_form_helpers_guide · 70009e31
      Kasper Timm Hansen 提交于
      Remove yepnope mention from form helpers guide because it's deprecated
      70009e31
    • A
    • S
      Cut string allocations in content_tag_string · e76a8435
      schneems 提交于
      content_tag's first argument is will generate a string with an html tag so `:a` will generate: `<a></a>`. When this happens, the symbol is implicitly `to_s`-d so a new string is allocated. We can get around that by using a frozen string instead which
      
      This change buys us 74,236 bytes of memory and 1,855 fewer objects per request.
      e76a8435
    • S
      Cut string ActionView template allocations · 9b189a31
      schneems 提交于
      The instrument method creates new strings, the most common action to instrument is "!render_template` so we can detect when that action is occurring and use a frozen string instead.
      
      This change buys us 113,714 bytes of memory and 1,790 fewer objects per request.
      9b189a31
    • S
      Optimize hash key · 2e95d2ef
      schneems 提交于
      No idea why on earth this hash key isn't already optimized by MRI, but it isn't. 💩
      
      This change buys us 74,077 bytes of memory and 1,852 fewer objects per request.
      2e95d2ef
    • S
      Decrease string allocation in content_tag_string · 2a4d4301
      schneems 提交于
      When an unknonwn key is passed to the hash in `PRE_CONTENT_STRINGS` it returns nil, when you call "#{nil}" it allocates a new empty string. We can get around this allocation by using a default value `Hash.new { "".freeze }`. We can avoid the `to_sym` call by pre-populating the hash with a symbol key in addition to a string key.
      
      We can freeze some strings when using Array#* to reduce allocations.
      
      Array#join can take frozen strings.
      
      This change buys us 86,600 bytes of memory and 1,857 fewer objects per request.
      2a4d4301
    • S
      Reduce hash allocations in route_set · 1a14074f
      schneems 提交于
      When generating a url with `url_for` the hash of arguments passed in, is dup-d and merged a TON. I wish I could clean this up better, and might be able to do it in the future. This change removes one dup, since it's literally right after we just dup-d the hash to pass into this constructor.
      
      This may be a breaking, change but the tests pass...so :shipit: we can revert if it causes problems
      
      This change buys us 205,933 bytes of memory and 887 fewer objects per request.
      1a14074f
    • S
      Decrease route_set allocations · 0cbec58a
      schneems 提交于
      In handle_positional_args `Array#-=` is used which allocates a new array. Instead we can iterate through and delete elements, modifying the array in place.
      
      Also `Array#take` allocates a new array. We can build the same by iterating over the other element.
      
      This change buys us 106,470 bytes of memory and 2,663 fewer objects per request.
      0cbec58a
    • S
      Speed up journey missing_keys · 097ec6fb
      schneems 提交于
      Most routes have a `route.path.requirements[key]` of `/[-_.a-zA-Z0-9]+\/[-_.a-zA-Z0-9]+/` yet every time this method is called a new regex is generated on the fly with `/\A#{DEFAULT_INPUT}\Z/`. OBJECT ALLOCATIONS BLERG!
      
      This change uses a special module that implements `===` so it can be used in a case statement to pull out the default input. When this happens, we use a pre-generated regex.
      
      This change buys us 1,643,465 bytes of memory and 7,990 fewer objects per request.
      097ec6fb
    • S
      Speed up journey extract_parameterized_parts · 9b825881
      schneems 提交于
      Micro optimization: `reverse.drop_while` is slower than `reverse_each.drop_while`. This doesn't save any object allocations.
      
      Second, `keys_to_keep` is typically a very small array. The operation `parameterized_parts.keys - keys_to_keep` actually allocates two arrays. It is quicker (I benchmarked) to iterate over each and check inclusion in array manually.
      
      This change buys us 1774 fewer objects per request
      9b825881
    • S
      Decrease string allocations in url_options · 83ee043c
      schneems 提交于
      The request.script_name is dup-d which allocates an extra string. It is most commonly an empty string "". We can save a ton of string allocations by checking first if the string is empty, if so we can use a frozen empty string instead of duplicating an empty string.
      
      This change buys us 35,714 bytes of memory and 893 fewer objects per request.
      83ee043c
    • S
      Decrease string allocations in apply_inflections · 1bf50bad
      schneems 提交于
      In `apply_inflections` a string is down cased and some whitespace stripped in the front (which allocate strings). This would normally be fine, however `uncountables` is a fairly small array (10 elements out of the box) and this method gets called a TON. Instead we can keep an array of valid regexes for each uncountable so we don't have to allocate new strings.
      
      This change buys us 325,106 bytes of memory and 3,251 fewer objects per request.
      1bf50bad
    • S
      Decrease string allocations on AR#respond_to? · f80aa599
      schneems 提交于
      When a symbol is passed in, we call `to_s` on it which allocates a string. The two hardcoded symbols that are used internally are `:to_partial_path` and `:to_model`.
      
      This change buys us 71,136 bytes of memory and 1,777 fewer objects per request.
      f80aa599
    • R
      Merge pull request #21065 from rails/schneems/fix-assets_test · 10e994cc
      Richard Schneeman 提交于
      Fix tests on master
      10e994cc
    • S
      Fix rake/notes_test · 9b18ba75
      schneems 提交于
      Presumably due to https://github.com/rails/sprockets-rails/pull/265 sprockets was trying to load the "scss" gem but it isn't in the gemfile:
      
      ```
      ApplicationTests::RakeTests::RakeNotesTest#test_register_a_new_extension:
      LoadError: cannot load such file -- sass
      ```
      
      If we use an empty precompile list, it won't try to load sass.
      9b18ba75
    • S
      Fix reported regression rails/sprockets-rails#265 · 4bc24691
      schneems 提交于
      We can prevent the UglifierCompressor from being instantiated prematurely by setting precompile to an empty array in this test.
      4bc24691
    • J
      Fix WARNINGS flag inside guides/Rakefile · 7fb8a7e5
      Jade Misenas 提交于
      7fb8a7e5
  5. 29 7月, 2015 1 次提交