aboutsummaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #30414 from bogdanvlviv/clear-mysql_database_tasksRafael França2017-11-093-139/+5
|\ | | | | Simplify implementation of `MySQLDatabaseTasks`
| * Simplify implementation of `MySQLDatabaseTasks`bogdanvlviv2017-10-303-135/+3
| | | | | | | | | | | | Don't process MySQL ERROR 1045, raise error instead Make behavior of `MySQLDatabaseTasks` more consistent with behavior of `PostgreSQLDatabaseTasks`
| * Raise error if unsupported charset for mysqlbogdanvlviv2017-10-302-7/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `blog$ bin/rails db:create` Before: ``` Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf42", "pool"=>5, "username"=>"root", "password"=>nil, "socket"=>"/var/run/mysqld/mysqld.sock", "database"=>"blog_development"}, {:charset=>"utf42"} (If you set the charset manually, make sure you have a matching collation) Created database 'blog_development' Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf42", "pool"=>5, "username"=>"root", "password"=>nil, "socket"=>"/var/run/mysqld/mysqld.sock", "database"=>"blog_test"}, {:charset=>"utf42"} (If you set the charset manually, make sure you have a matching collation) Created database 'blog_test' ``` After: ``` Unsupported charset: '"utf42"' Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf42", "pool"=>5, "username"=>"root", "password"=>nil, "socket"=>"/var/run/mysqld/mysqld.sock", "database"=>"blog_development"} rails aborted! Mysql2::Error: Unsupported charset: '"utf42"' ... (stack trace) ... bin/rails:4:in `<main>' Tasks: TOP => db:create (See full trace by running task with --trace) ``` Closes #29683 Related to #27398
* | Merge pull request #25346 from bogdan/correct-tags-count-in-fixturesRafael França2017-11-095-11/+20
|\ \ | | | | | | Set counter caches to correct values in fixtures
| * | Set counter caches to correct values in fixturesBogdan Gusiev2017-11-085-11/+20
| | |
* | | Merge pull request #30985 from lugray/attribute_set_in_amRafael França2017-11-0922-236/+225
|\ \ \ | | | | | | | | Move Attribute and AttributeSet to ActiveModel
| * | | Move Attribute and AttributeSet to ActiveModelLisa Ugray2017-11-0922-236/+225
|/ / / | | | | | | | | | | | | Use these to back the attributes API. Stop automatically including ActiveModel::Dirty in ActiveModel::Attributes, and make it optional.
* | | Merge pull request #31088 from neumayr/am-helper-missing-field_with_errorsRafael França2017-11-094-3/+104
|\ \ \ | | | | | | | | field_error_proc wrap form select optgroup and separator option
| * | | Fix field_error_proc wrap form select optgroup and divider option tagneumayr2017-11-094-3/+104
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ### Summary The [`:field_error_proc`](https://github.com/rails/rails/blob/master/actionview/lib/action_view/base.rb#L145) is responsible for decorating input tags that refer to attributes with errors. This default build-in rails feature wrap invalid form elements with additional markup: `<div class="field_with_errors">[…]</div>`. * Fix for `field_error_proc` wraps form select `optgroup` * Fix for `field_error_proc` wraps form select divider `option` * Add tests for uncovered elements with errors [Fixes #31088] #### Test coverage * `test_select_grouped_options_with_errors` * `test_time_zone_select_with_priority_zones_and_errors` #### Extend test coverage * `test_collection_select_with_errors` * `test_label_with_errors` * `test_check_box_with_errors` * `test_check_boxes_with_errors` * `test_radio_button_with_errors` * `test_radio_buttons_with_errors` * `test_collection_check_boxes_with_errors` * `test_collection_radio_buttons_with_errors`
* | | | Merge pull request #31099 from nobu/patch-1Rafael Mendonça França2017-11-091-1/+1
|\ \ \ \ | | | | | | | | | | | | | | | Use `Tempfile.create`
| * | | | Use `Dir.mktmpdir`Nobuyoshi Nakada2017-11-091-1/+1
| | | | | | | | | | | | | | | | | | | | As `@cache_path` is expected to be a directory name, use `Dir.mktmpdir`. And omit unnecessary `Dir.tmpdir`.
| * | | | Use `Tempfile.create`Nobuyoshi Nakada2017-11-091-1/+1
| | | | | | | | | | | | | | | Instead of `Dir::Tmpname.make_tmpname`, an internal method which does not guarantee uniqueness, use `Tempfile.create`.
* | | | | Merge pull request #31081 from rails/allow-include-time-with-zone-rangeAndrew White2017-11-095-4/+46
|\ \ \ \ \ | | | | | | | | | | | | Allow `Range#include?` on TWZ ranges
| * | | | | Allow `Range#include?` on TWZ rangesAndrew White2017-11-085-4/+46
| | |_|/ / | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In #11474 we prevented TWZ ranges being iterated over which matched Ruby's handling of Time ranges and as a consequence `include?` stopped working with both Time ranges and TWZ ranges. However in ruby/ruby@b061634 support was added for `include?` to use `cover?` for 'linear' objects. Since we have no way of making Ruby consider TWZ instances as 'linear' we have to override `Range#include?`. Fixes #30799.
* | | | | Merge pull request #31102 from y-yagi/do_not_show_credentials_in_generators_helpEileen M. Uchitelle2017-11-092-1/+3
|\ \ \ \ \ | |_|/ / / |/| | | | Do not show credentials in generators help
| * | | | Do not show credentials in generators helpyuuji.yaginuma2017-11-092-1/+3
|/ / / / | | | | | | | | | | | | | | | | | | | | Since credentials generator is executed via the credentials command and does not need to be executed directly, so it is not necessary to show it in help.
* | | | Should pass `test_no_locks_no_wait` not only on `PostgreSQLAdapter` and ↵Ryuta Kamizono2017-11-091-8/+5
| | | | | | | | | | | | | | | | `OracleAdapter`
* | | | Merge pull request #31077 from gsamokovarov/assert-changes-nilRafael França2017-11-092-9/+5
|\ \ \ \ | | | | | | | | | | Use plain assert in assert_changes to avoid MT6 refutes
| * | | | Use plain assert in assert_changes to avoid MT6 refutesGenadi Samokovarov2017-11-072-9/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Seeing the previously issued PRs about it, we can avoid the `nil` comparisons that can happen in `assert_changes` by using plain `assert` calls. This is to avoid a deprecation warning about comparing `nil` values in `assert_equal` for Minitest 5 and a crash in Minitest 6. You can see the preparations done in [`assert_equal`][ae]. You can also see that [`assert`][a] does not care about `nil`s. [ae]: https://github.com/seattlerb/minitest/blob/ca6a71ca901016db09a5ad466b4adea4b52a504a/lib/minitest/assertions.rb#L159-L188 [a]: https://github.com/seattlerb/minitest/blob/ca6a71ca901016db09a5ad466b4adea4b52a504a/lib/minitest/assertions.rb#L131-L142
* | | | | Merge pull request #31078 from aeroastro/feature/fix-typoRafael França2017-11-091-2/+2
|\ \ \ \ \ | | | | | | | | | | | | Fix typoes on ActionDispatch::HTTP::FilterParameters
| * | | | | Fix typo on ActionDispatc::HTTP::FilterParametersTakumasa Ochi2017-11-071-2/+2
| | | | | |
* | | | | | Merge pull request #31095 from y-yagi/correctly_kill_the_server_in_ujs_testRafael França2017-11-081-2/+2
|\ \ \ \ \ \ | | | | | | | | | | | | | | Correctly kill the server started with ujs test
| * | | | | | Correctly kill the server started with ujs testyuuji.yaginuma2017-11-091-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `Kernel.#spawn` execute command via the shell if contains shell metacharacters in the command. In that case, return value of `spawn` is pid of the shell, not the server. Therefore, just killing the pid will leave the process of server. In order to correctly kill the server, send a signal to the process group, not the process.
* | | | | | | Merge pull request #31091 from yahonda/concurrent_transaction_test_conditionsRafael França2017-11-081-15/+13
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | Allow `ConcurrentTransactionTest` can run with Oracle enhanced adapter
| * | | | | | | Run `ConcurrentTransactionTest` if `supports_transaction_isolation?`Yasuo Honda2017-11-081-15/+13
| |/ / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | returns true Not only postgresql or mysql2 adapter, Oracle enhanced adapter whose default isolation level is read commited, passes these two test cases. `ConcurrentTransactionTest#test_transaction_per_thread` `ConcurrentTransactionTest#test_transaction_isolation__read_committed` ```ruby $ ARCONN=oracle bin/test test/cases/transactions_test.rb:961 -v Using oracle Run options: -v --seed 18865 ConcurrentTransactionTest#test_transaction_per_thread = 0.98 s = . Finished in 1.061036s, 0.9425 runs/s, 5.6549 assertions/s. 1 runs, 6 assertions, 0 failures, 0 errors, 0 skips ``` ```ruby $ ARCONN=oracle bin/test test/cases/transactions_test.rb:979 -v Using oracle Run options: -v --seed 13341 ConcurrentTransactionTest#test_transaction_isolation__read_committed = 1.85 s = . Finished in 1.928637s, 0.5185 runs/s, 10.3700 assertions/s. 1 runs, 20 assertions, 0 failures, 0 errors, 0 skips $ ``` Also, regardless it is a file based or memory based these tests could fail with SQLite3Adapter. (Extra CR added to make lines shorter) ```ruby $ ARCONN=sqlite3 bin/test test/cases/transactions_test.rb:961 -v Using sqlite3 Run options: -v --seed 18815 ConcurrentTransactionTest#test_transaction_per_thread = /home/yahonda/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sqlite3-1.3.13/lib/sqlite3/statement.rb:108:in `step': SQLite3::BusyException: database is locked: UPDATE "topics" SET "approved" = ?, "updated_at" = ? WHERE "topics"."id" = ? (ActiveRecord::StatementInvalid) ``` ```ruby $ ARCONN=sqlite3 bin/test test/cases/transactions_test.rb:979 -v Using sqlite3 Run options: -v --seed 25520 ConcurrentTransactionTest#test_transaction_isolation__read_committed = 0.12 s = E /home/yahonda/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sqlite3-1.3.13/lib/sqlite3/statement.rb:108:in `step': SQLite3::BusyException: database is locked: UPDATE "developers" SET "salary" = ?, "updated_at" = ?, "updated_on" = ? WHERE "developers"."id" = ? (ActiveRecord::StatementInvalid) ```
* | | | | | | Merge pull request #31093 from bogdanvlviv/express-console-command-in-the-logRafael França2017-11-081-1/+1
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | Change output log about skipping instalation of Active Storage
| * | | | | | | Change output log about skipping instalation of Active Storagebogdanvlviv2017-11-081-1/+1
| |/ / / / / / | | | | | | | | | | | | | | | | | | | | | Using of "`" is preferable over "'" to express console command in output log
* | | | | | | Merge pull request #31092 from ↵Rafael França2017-11-085-6/+6
|\ \ \ \ \ \ \ | |/ / / / / / |/| | | | | | | | | | | | | | | | | | | | bogdanvlviv/remove-redundant-passing-skip-active-storage-in-test-cases Remove redundant passing --skip-active-storage in test cases
| * | | | | | Remove redundant passing --skip-active-storage in test casesbogdanvlviv2017-11-085-6/+6
|/ / / / / / | | | | | | | | | | | | | | | | | | These were added in #30101, after #31084 it became redundant.
* | | | | | `Mysql2Adapter` should pass `ConcurrentTransactionTest`Ryuta Kamizono2017-11-091-1/+1
| | | | | |
* | | | | | Consolidate redundant `if` and `unless` with the same conditionRyuta Kamizono2017-11-091-3/+1
| | | | | |
* | | | | | Don't expose accessors which are internal used onlyRyuta Kamizono2017-11-082-3/+6
| |_|_|/ / |/| | | |
* | | | | Don't expose internal methods in `Preloader::ThroughAssociation`Ryuta Kamizono2017-11-081-8/+7
| | | | | | | | | | | | | | | | | | | | `through_reflection` and `source_reflection` are used only in the class.
* | | | | Merge pull request #31086 from y-yagi/use_released_redis_namespaceMatthew Draper2017-11-082-10/+4
|\ \ \ \ \ | | | | | | | | | | | | Use released `redis-namespace` instead of master version
| * | | | | Use released `redis-namespace` instead of master versionyuuji.yaginuma2017-11-082-10/+4
| | | | | | | | | | | | | | | | | | | | | | | | The `redis-namespace` 1.6.0 includes redis-rb 4.0 support.
* | | | | | Merge pull request #31085 from ↵Ryuta Kamizono2017-11-081-1/+1
|\ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | y-yagi/fix_output_of_select_tag_with_include_blank_true Fix output of `select_tag` with `include_blank: true` [ci skip]
| * | | | | | Fix output of `select_tag` with `include_blank: true` [ci skip]yuuji.yaginuma2017-11-081-1/+1
| |/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | Since #24923, if use `select_tag` with `include_blank: true`, an empty label is added.
* | | | | | Merge pull request #31084 from ↵Ryuta Kamizono2017-11-089-22/+24
|\ \ \ \ \ \ | |/ / / / / |/| | | | | | | | | | | | | | | | | y-yagi/do_not_run_active_storage_install_when_bundle_install_is_skipped Do not run active storage install when bundle install is skipped
| * | | | | Remove unnecessary migration deletionyuuji.yaginuma2017-11-085-19/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since isolation application is generated with the `--skip-gemfile` option, so `active_storage:install` is not executed.
| * | | | | Do not run `active_storage:install` when bundle install is skippedyuuji.yaginuma2017-11-084-3/+24
|/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In order to execute the `rails` command, need to run bundle install in advance. Therefore, if skipped bundle install, `rails` command may fail and should not do it.
* | | / / Remove needless block parameterGeorge Claghorn2017-11-071-1/+1
| |_|/ / |/| | |
* | | | Merge pull request #31076 from y-yagi/fix_comment_in_check_class_collisionRyuta Kamizono2017-11-071-1/+1
|\ \ \ \ | | | | | | | | | | Fix comment in `check_class_collision` [ci skip]
| * | | | Fix comment in `check_class_collision` [ci skip]yuuji.yaginuma2017-11-071-1/+1
| | | | | | | | | | | | | | | | | | | | `ScaffoldBase` was changed to `ResourceHelpers` by 0efedf2.
* | | | | Merge pull request #30997 from q-centrix/nofollow-changeRafael França2017-11-061-3/+7
|\ \ \ \ \ | |/ / / / |/| | | | Prevent extra string allocations when no 'rel' arg passed
| * | | | Merge remote-tracking branch 'upstream/master' into nofollow-changeDillon Welch2017-11-0367-174/+204
| |\ \ \ \
| * | | | | Fix typoDillon Welch2017-11-021-1/+1
| | | | | |
| * | | | | Remove test fileDillon Welch2017-11-021-110/+0
| | | | | |
| * | | | | Use blank? check instead of key? checkDillon Welch2017-11-022-3/+113
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This allows us to prevent an extra string allocation when there is a rel argument and performs better/within error of the key check for other scenarios such as passing in rel: nil ```ruby begin require "bundler/inline" rescue LoadError => e $stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" raise e end gemfile(true) do source "https://rubygems.org" gem "benchmark-ips" gem "rails" end def allocate_count GC.disable before = ObjectSpace.count_objects yield after = ObjectSpace.count_objects after.each { |k,v| after[k] = v - before[k] } after[:T_HASH] -= 1 # probe effect - we created the before hash. GC.enable result = after.reject { |k,v| v == 0 } GC.start result end @hash = {} def master_version "#{@hash["rel"]} nofollow".lstrip end def key_version if @hash.key?("rel") "#{@hash["rel"]} nofollow".lstrip else "nofollow" end end def present_version if @hash["rel"].present? "#{@hash["rel"]} nofollow" else "nofollow".freeze end end def nil_version if @hash["rel"].nil? "nofollow".freeze else "#{@hash["rel"]} nofollow" end end def blank_version if @hash["rel"].blank? "nofollow".freeze else "#{@hash["rel"]} nofollow" end end def test puts "master_version" puts allocate_count { 1000.times { master_version } } puts "key_version" puts allocate_count { 1000.times { key_version } } puts "present_version" puts allocate_count { 1000.times { present_version } } puts "nil_version" puts allocate_count { 1000.times { nil_version } } puts "blank_version" puts allocate_count { 1000.times { blank_version } } Benchmark.ips do |x| x.report("master_version") { master_version } x.report("key_version") { key_version } x.report("present_version") { present_version } x.report("nil_version") { nil_version } x.report("blank_version") { blank_version } x.compare! end end puts 'no rel key' test puts 'rel key with real stuff' @hash['rel'] = 'hi'.freeze test puts 'rel key with nil' @hash['rel'] = nil test puts 'rel key with ""' @hash['rel'] = "" test ``` ``` no rel key master_version {:FREE=>-2818, :T_STRING=>3052} key_version {:FREE=>-1} present_version {:FREE=>-1} nil_version {:FREE=>-1} blank_version {:FREE=>-1} Warming up -------------------------------------- master_version 124.677k i/100ms key_version 227.992k i/100ms present_version 208.068k i/100ms nil_version 235.272k i/100ms blank_version 176.274k i/100ms Calculating ------------------------------------- master_version 1.968M (±10.8%) i/s - 9.725M in 5.010763s key_version 7.734M (±11.2%) i/s - 38.075M in 5.001613s present_version 5.688M (±11.4%) i/s - 28.089M in 5.019560s nil_version 6.965M (±10.2%) i/s - 34.585M in 5.024806s blank_version 6.139M (±18.7%) i/s - 29.085M in 5.010919s Comparison: key_version: 7734058.3 i/s nil_version: 6965050.2 i/s - same-ish: difference falls within error blank_version: 6138744.3 i/s - same-ish: difference falls within error present_version: 5688248.4 i/s - 1.36x slower master_version: 1967932.3 i/s - 3.93x slower rel key with real stuff master_version {:FREE=>-2001, :T_STRING=>2000} key_version {:FREE=>-2001, :T_STRING=>2000} present_version {:FREE=>-1001, :T_STRING=>1000} nil_version {:FREE=>-1002, :T_STRING=>1000, :T_IMEMO=>1} blank_version {:FREE=>-1001, :T_STRING=>1000} Warming up -------------------------------------- master_version 93.351k i/100ms key_version 89.747k i/100ms present_version 91.963k i/100ms nil_version 103.370k i/100ms blank_version 74.845k i/100ms Calculating ------------------------------------- master_version 2.179M (±21.4%) i/s - 10.362M in 5.044668s key_version 2.345M (± 9.8%) i/s - 11.667M in 5.030982s present_version 1.738M (±14.8%) i/s - 8.553M in 5.056406s nil_version 2.485M (±19.1%) i/s - 11.888M in 5.015940s blank_version 1.951M (±12.3%) i/s - 9.580M in 5.011932s Comparison: nil_version: 2484704.1 i/s key_version: 2344664.8 i/s - same-ish: difference falls within error master_version: 2178975.8 i/s - same-ish: difference falls within error blank_version: 1950532.0 i/s - same-ish: difference falls within error present_version: 1737866.7 i/s - 1.43x slower rel key with nil master_version {:FREE=>-3001, :T_STRING=>3000} key_version {:FREE=>-3001, :T_STRING=>3000} present_version {:FREE=>-1} nil_version {:FREE=>-1} blank_version {:FREE=>-1} Warming up -------------------------------------- master_version 112.655k i/100ms key_version 105.048k i/100ms present_version 136.219k i/100ms nil_version 192.026k i/100ms blank_version 184.846k i/100ms Calculating ------------------------------------- master_version 1.893M (±12.6%) i/s - 9.238M in 5.002621s key_version 1.672M (±13.5%) i/s - 8.194M in 5.021197s present_version 4.484M (±20.5%) i/s - 21.114M in 5.002982s nil_version 5.294M (±18.1%) i/s - 25.155M in 5.020721s blank_version 5.588M (± 6.7%) i/s - 27.912M in 5.019305s Comparison: blank_version: 5588489.6 i/s nil_version: 5293929.9 i/s - same-ish: difference falls within error present_version: 4484493.7 i/s - same-ish: difference falls within error master_version: 1892919.0 i/s - 2.95x slower key_version: 1672343.9 i/s - 3.34x slower rel key with "" master_version {:FREE=>-2001, :T_STRING=>2000} key_version {:FREE=>-2001, :T_STRING=>2000} present_version {:FREE=>-1} nil_version {:FREE=>-1001, :T_STRING=>1000} blank_version {:FREE=>-1} Warming up -------------------------------------- master_version 140.499k i/100ms key_version 124.738k i/100ms present_version 186.659k i/100ms nil_version 148.063k i/100ms blank_version 178.707k i/100ms Calculating ------------------------------------- master_version 1.826M (±24.2%) i/s - 8.289M in 5.026603s key_version 1.561M (±15.3%) i/s - 7.609M in 5.005662s present_version 3.622M (±19.9%) i/s - 17.173M in 5.042217s nil_version 2.438M (±11.5%) i/s - 12.141M in 5.053335s blank_version 4.911M (±15.5%) i/s - 23.768M in 5.009106s Comparison: blank_version: 4910741.1 i/s present_version: 3622183.5 i/s - same-ish: difference falls within error nil_version: 2437606.2 i/s - 2.01x slower master_version: 1825652.2 i/s - 2.69x slower key_version: 1560530.5 i/s - 3.15x slower ```
| * | | | | Prevent extra string allocations when no 'rel' arg passedDillon Welch2017-10-261-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Do a check if the 'rel' argument is passed in, and simply set it to 'nofollow' if 'rel' was not passed in. This prevents three string allocations for each call to `link_to` in that scenario. In the scenario where the 'rel' argument is passed in, performance is around the same as before as the `key?` check is very fast. ```ruby begin require "bundler/inline" rescue LoadError => e $stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" raise e end gemfile(true) do source "https://rubygems.org" gem "benchmark-ips" gem "rails" end def allocate_count GC.disable before = ObjectSpace.count_objects yield after = ObjectSpace.count_objects after.each { |k,v| after[k] = v - before[k] } after[:T_HASH] -= 1 # probe effect - we created the before hash. GC.enable result = after.reject { |k,v| v == 0 } GC.start result end @hash = {} def master_version "#{@hash['rel'.freeze]} nofollow".lstrip end def fast_version if @hash.key?('rel'.freeze) "#{@hash["rel"]} nofollow".lstrip else "nofollow".freeze end end puts 'no rel key' puts "master_version" puts allocate_count { 1000.times { master_version } } puts "fast_version" puts allocate_count { 1000.times { fast_version } } Benchmark.ips do |x| x.report("master_version") { master_version } x.report("fast_version") { fast_version } x.compare! end puts 'rel key' @hash['rel'] = 'hi'.freeze puts "master_version" puts allocate_count { 1000.times { master_version } } puts "fast_version" puts allocate_count { 1000.times { fast_version } } Benchmark.ips do |x| x.report("master_version") { master_version } x.report("fast_version") { fast_version } x.compare! end ``` ``` no rel key master_version {:FREE=>-2791, :T_STRING=>3052} fast_version {:FREE=>-1} Warming up -------------------------------------- master_version 80.324k i/100ms fast_version 200.262k i/100ms Calculating ------------------------------------- master_version 2.049M (±11.9%) i/s - 10.121M in 5.025613s fast_version 6.645M (±21.3%) i/s - 29.439M in 5.007488s Comparison: fast_version: 6644506.3 i/s master_version: 2048833.0 i/s - 3.24x slower rel key master_version {:FREE=>-2001, :T_STRING=>2000} fast_version {:FREE=>-2001, :T_STRING=>2000} Warming up -------------------------------------- master_version 155.673k i/100ms fast_version 106.515k i/100ms Calculating ------------------------------------- master_version 2.652M (±20.4%) i/s - 12.610M in 5.036494s fast_version 2.237M (±16.8%) i/s - 10.865M in 5.035366s Comparison: master_version: 2651702.2 i/s fast_version: 2237470.6 i/s - same-ish: difference falls within error ```
* | | | | | Merge pull request #31061 from ↵Rafael França2017-11-065-7/+62
|\ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | bogdanvlviv/test-if-unless-options-for-validations Add cases to test combining validation conditions