Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundMethod#bind_call #77

Closed
znz opened this issue Oct 3, 2019 · 0 comments · Fixed by #92
Closed

UnboundMethod#bind_call #77

znz opened this issue Oct 3, 2019 · 0 comments · Fixed by #92

Comments

@znz
Copy link

znz commented Oct 3, 2019

Is your feature request related to a problem? Please describe.

Added umethod.bind_call(obj, ...) for faster replacement of umethod.bind(obj).call(...) in Ruby 2.7.
See https://bugs.ruby-lang.org/issues/15955 for details.

Describe the solution you'd like

Suggest bind_call(obj, ...) when bind(obj).call(...) used.

koic added a commit to koic/rubocop-performance that referenced this issue Jan 7, 2020
Fixes rubocop#77.

This PR adds new `Performance/BindCall` cop.

In Ruby 2.7, `UnboundMethod#bind_call` have been added.

- https://bugs.ruby-lang.org/issues/15955
- ruby/ruby@83c6a1e

The `bind_call(obj, args, ...)` method is faster than
`bind(obj).call(args, ...)`.

```console
% ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin17]

% gem i benchmark-ips
(snip)

% cat bench.rb
require 'benchmark/ips'

Benchmark.ips do |x|
  umethod = String.instance_method(:start_with?)

  x.report('bind.call') { umethod.bind('hello, world').call('hello') }
  x.report('bind_call') { umethod.bind_call('hello, world', 'hello') }

  x.compare!
end

% ruby bench.rb
Warming up --------------------------------------
           bind.call   122.167k i/100ms
           bind_call   189.749k i/100ms
Calculating -------------------------------------
           bind.call      1.795M (± 1.7%) i/s -      9.040M in   5.039135s
           bind_call      3.756M (± 2.2%) i/s -     18.785M in   5.004573s

Comparison:
           bind_call:  3755510.3 i/s
           bind.call:  1794560.4 i/s - 2.09x  slower
```
koic added a commit to koic/rubocop-performance that referenced this issue Jan 7, 2020
Fixes rubocop#77.

This PR adds new `Performance/BindCall` cop.

In Ruby 2.7, `UnboundMethod#bind_call` has been added.

- https://bugs.ruby-lang.org/issues/15955
- ruby/ruby@83c6a1e

The `bind_call(obj, args, ...)` method is faster than
`bind(obj).call(args, ...)`.

```console
% ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin17]

% gem i benchmark-ips
(snip)

% cat bench.rb
require 'benchmark/ips'

Benchmark.ips do |x|
  umethod = String.instance_method(:start_with?)

  x.report('bind.call') { umethod.bind('hello, world').call('hello') }
  x.report('bind_call') { umethod.bind_call('hello, world', 'hello') }

  x.compare!
end

% ruby bench.rb
Warming up --------------------------------------
           bind.call   122.167k i/100ms
           bind_call   189.749k i/100ms
Calculating -------------------------------------
           bind.call      1.795M (± 1.7%) i/s -      9.040M in   5.039135s
           bind_call      3.756M (± 2.2%) i/s -     18.785M in   5.004573s

Comparison:
           bind_call:  3755510.3 i/s
           bind.call:  1794560.4 i/s - 2.09x  slower
```
koic added a commit to koic/rubocop-performance that referenced this issue Jan 7, 2020
Fixes rubocop#77.

This PR adds new `Performance/BindCall` cop.

In Ruby 2.7, `UnboundMethod#bind_call` has been added.

- https://bugs.ruby-lang.org/issues/15955
- ruby/ruby@83c6a1e

The `bind_call(obj, args, ...)` method is faster than
`bind(obj).call(args, ...)`.

```console
% ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin17]

% gem i benchmark-ips
(snip)

% cat bench.rb
require 'benchmark/ips'

Benchmark.ips do |x|
  umethod = String.instance_method(:start_with?)

  x.report('bind.call') { umethod.bind('hello, world').call('hello') }
  x.report('bind_call') { umethod.bind_call('hello, world', 'hello') }

  x.compare!
end

% ruby bench.rb
Warming up --------------------------------------
           bind.call   122.167k i/100ms
           bind_call   189.749k i/100ms
Calculating -------------------------------------
           bind.call      1.795M (± 1.7%) i/s -      9.040M in   5.039135s
           bind_call      3.756M (± 2.2%) i/s -     18.785M in   5.004573s

Comparison:
           bind_call:  3755510.3 i/s
           bind.call:  1794560.4 i/s - 2.09x  slower
```
koic added a commit to koic/rubocop-performance that referenced this issue Jan 7, 2020
Fixes rubocop#77.

This PR adds new `Performance/BindCall` cop.

In Ruby 2.7, `UnboundMethod#bind_call` has been added.

- https://bugs.ruby-lang.org/issues/15955
- ruby/ruby@83c6a1e

The `bind_call(obj, args, ...)` method is faster than
`bind(obj).call(args, ...)`.

```console
% ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin17]

% gem i benchmark-ips
(snip)

% cat bench.rb
require 'benchmark/ips'

Benchmark.ips do |x|
  umethod = String.instance_method(:start_with?)

  x.report('bind.call') { umethod.bind('hello, world').call('hello') }
  x.report('bind_call') { umethod.bind_call('hello, world', 'hello') }

  x.compare!
end

% ruby bench.rb
Warming up --------------------------------------
           bind.call   122.167k i/100ms
           bind_call   189.749k i/100ms
Calculating -------------------------------------
           bind.call      1.795M (± 1.7%) i/s -      9.040M in   5.039135s
           bind_call      3.756M (± 2.2%) i/s -     18.785M in   5.004573s

Comparison:
           bind_call:  3755510.3 i/s
           bind.call:  1794560.4 i/s - 2.09x  slower
```
@koic koic closed this as completed in #92 Jan 8, 2020
koic added a commit that referenced this issue Jan 8, 2020
[Fix #77] Add new `Performance/BindCall` cop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants