Disable Style/ExplicitBlockArgument cop rule
What does this MR do and why?
This MR disables Style/ExplicitBlockArgument
.
Reason: Using yield
is ~20% faster than &block
.
See gitlab-org/gitlab!94090 (comment 1452639709)
gitlab-org/gitlab
Impact on After disabling this
Follow-ups
Note that there's no yield
.
Style/BlockArgument
- Create
🆕 Style/BlockArgument
- Configure it with `EnforcedStyle'
-
explicit
(default, seeStyle/ExplicitBlockArgument
) -&block
+&block
-
implicit
-&
+&
- see https://bugs.ruby-lang.org/issues/11256 -
yield
-none
+yield
-
OR
Performance/NoBlockArgument
- Create
🆕 :copPerformance/NoBlockArgument
to flag the use ofdef x(&block)
and suggestyield
instead. - Mention the conflict with
Style/ExplicitBlockArgument
Benchmarks
From gitlab-org/gitlab!94090 (comment 1452639709)
Ruby: 3.1.4
# frozen_string_literal: true
require 'benchmark/ips'
def calling
:ok
end
def explicit(&block)
calling(&block)
end
# https://bugs.ruby-lang.org/issues/11256
def implicit(&)
calling(&)
end
def yielding
calling { yield }
end
Benchmark.ips do |x|
x.report('explicit') { explicit { :ok } }
x.report('implicit') { implicit { :ok } }
x.report('yield') { yielding { :ok } }
x.compare!
end
Warming up --------------------------------------
explicit 1.594M i/100ms
implicit 1.652M i/100ms
yield 2.208M i/100ms
Calculating -------------------------------------
explicit 16.135M (± 2.4%) i/s - 81.270M in 5.040211s
implicit 16.168M (± 4.2%) i/s - 80.945M in 5.015849s
yield 19.618M (± 0.9%) i/s - 99.350M in 5.064509s
Comparison:
yield: 19618467.3 i/s
implicit: 16168012.7 i/s - 1.21x slower
explicit: 16135291.8 i/s - 1.22x slower
Same results for Ruby 3.2.2.
Edited by Peter Leitzen