Skip to content

Commit

Permalink
[Fix #385] Disable Performance/BlockGivenWithExplicitBlock by default
Browse files Browse the repository at this point in the history
See linked issue for benchmark details.

I tested with YJIT and its even worse:
```
ruby 3.4.0dev (2024-09-05T09:43:46Z master 63cbe3f6ac) +YJIT [x86_64-linux]
Warming up --------------------------------------
               block     1.635M i/100ms
      block w/ block   285.930k i/100ms
        block_given?     1.867M i/100ms
block_given? w/ block
                         1.497M i/100ms
Calculating -------------------------------------
               block     22.611M (±12.7%) i/s   (44.23 ns/i) -    111.180M in   5.033721s
      block w/ block      3.034M (± 8.5%) i/s  (329.59 ns/i) -     15.154M in   5.032609s
        block_given?     24.935M (±10.7%) i/s   (40.10 ns/i) -    123.254M in   5.002983s
block_given? w/ block
                         23.007M (±14.7%) i/s   (43.47 ns/i) -    113.782M in   5.058213s

Comparison:
        block_given?: 24935388.3 i/s
block_given? w/ block: 23006920.5 i/s - same-ish: difference falls within error
               block: 22610939.8 i/s - same-ish: difference falls within error
      block w/ block:  3034047.2 i/s - 8.22x  slower
```
  • Loading branch information
Earlopain committed Sep 13, 2024
1 parent 082d635 commit 8907a12
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/change_disable_block_given.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#385](https://github.com/rubocop/rubocop-performance/issues/385): Disable `Performance/BlockGivenWithExplicitBlock` by default. ([@earlopain][])
5 changes: 4 additions & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ Performance/BindCall:

Performance/BlockGivenWithExplicitBlock:
Description: 'Check block argument explicitly instead of using `block_given?`.'
Enabled: pending
# This cop was created due to a mistake in microbenchmark.
# https://github.com/rubocop/rubocop-performance/issues/385
Enabled: false
VersionAdded: '1.9'
VersionChanged: <<next>>

Performance/Caller:
Description: >-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module Performance
# Identifies unnecessary use of a `block_given?` where explicit check
# of block argument would suffice.
#
# NOTE: This cop produces code with significantly worse performance when a
# block is being passed to the method and as such should not be enabled.
#
# @example
# # bad
# def method(&block)
Expand Down

0 comments on commit 8907a12

Please sign in to comment.