Skip to content

Commit 8907a12

Browse files
committed
[Fix #385] Disable Performance/BlockGivenWithExplicitBlock by default
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 ```
1 parent 082d635 commit 8907a12

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#385](https://github.com/rubocop/rubocop-performance/issues/385): Disable `Performance/BlockGivenWithExplicitBlock` by default. ([@earlopain][])

config/default.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ Performance/BindCall:
3232

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

3841
Performance/Caller:
3942
Description: >-

lib/rubocop/cop/performance/block_given_with_explicit_block.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ module Performance
66
# Identifies unnecessary use of a `block_given?` where explicit check
77
# of block argument would suffice.
88
#
9+
# NOTE: This cop produces code with significantly worse performance when a
10+
# block is being passed to the method and as such should not be enabled.
11+
#
912
# @example
1013
# # bad
1114
# def method(&block)

0 commit comments

Comments
 (0)