ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:90294] [Ruby trunk Feature#15380] faster method lookup for Array#all? #none? #one?
       [not found] <redmine.issue-15380.20181205042657@ruby-lang.org>
@ 2018-12-05  4:26 ` fursich0
  2018-12-05  4:55 ` [ruby-core:90295] " ko1
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: fursich0 @ 2018-12-05  4:26 UTC (permalink / raw)
  To: ruby-core

Issue #15380 has been reported by fursich (Onishi Koji).

----------------------------------------
Feature #15380: faster method lookup for Array#all? #none?  #one?
https://bugs.ruby-lang.org/issues/15380

* Author: fursich (Onishi Koji)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
## summary

This PR proposes Array-specific implementations for `#all?` , `#none?` and `#one?` to enable faster method lookup.

Before this patch `Array#all?` was not implemented in Array class, so alternatively, `Enumerable#all?` was used each time the method is called.

On the other hand, `#any?` has its own method entry in Array class for faster method calls.

This patch provides above three methods with Array-specific implementations that are equivalent to what `Array#any?` has.


https://github.com/ruby/ruby/pull/2041



## benchmark


~~~ text
**********************************************************************************
benchmarking Array#all?
**********************************************************************************

Calculating -------------------------------------
    Array#all? (new)          421.298 i/s -      1.000k times in 2.373616s (2.37ms/i)
    Array#all? (old)          335.364 i/s -      1.000k times in 2.981838s (2.98ms/i)

Comparison:
    Array#all? (new):       421.3 i/s
    Array#all? (old):       335.4 i/s - 1.26x  slower

<running with --jit>
Calculating -------------------------------------
    Array#all? (new)                244.929 i/s -      1.000k times in 4.082823s (4.08ms/i)
    Array#all? (old)                210.354 i/s -      1.000k times in 4.753895s (4.75ms/i)

Comparison:
    Array#all? (new):       244.9 i/s
    Array#all? (old):       210.4 i/s - 1.16x  slower
~~~

Attached benchmark shows the full benchmark results:

https://gist.github.com/fursich/1d1bad353ddc2f4b510b34e3191fd302


Each method gets approx. 10-20% faster with repeated calls.
It only impacts on method lookup (not execution itself), but at least it should make` Array#all?` work as just efficiently as `Array#any?` does.


## estimate of impact

Just to provide a rough picture on how frequently these methods are used in real world app, here shows a quick-and-dirty investigations I did with [rails](https://github.com/rails/rails) (using its latest master as of Dec 5):

~~~ text
rails (master)$ git grep '\.all?' | wc -l
      80
rails (master)$ git grep '\.one?' | wc -l
      13
rails (master)$ git grep '\.none?' | wc -l
      25
~~~

while
~~~ text
rails (master)$ git grep '\.any?' | wc -l
~~~

(* the result includes non-Array method. the intention here is just to give rough estimate on how frequently these methods are used compared with each other)

It's probably fair to say the use of the three methods (118 lines in total here) are *not* ignorably rare compared to `#all?`


## motivation behind it

In developing Ruby apps we encounter (often non essential) discussion around 'which method call is faster?', 'should we use this method for efficiency?'.

As Ruby lover I really hope to pick methods based on pure readability and Ruby-ness, 

Hopefully it helps Ruby become faster even at slightest level :)




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:90295] [Ruby trunk Feature#15380] faster method lookup for Array#all? #none? #one?
       [not found] <redmine.issue-15380.20181205042657@ruby-lang.org>
  2018-12-05  4:26 ` [ruby-core:90294] [Ruby trunk Feature#15380] faster method lookup for Array#all? #none? #one? fursich0
@ 2018-12-05  4:55 ` ko1
  2018-12-05  6:23 ` [ruby-core:90298] " shevegen
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: ko1 @ 2018-12-05  4:55 UTC (permalink / raw)
  To: ruby-core

Issue #15380 has been updated by ko1 (Koichi Sasada).


If we introduce special versions for Array, some new code are introduced.
It means the code we need to maintain will be increased.

I think about 20% improvement is not worth compare with the disadvantage.

BTW, I don't check the patch and benchmark code, the length of Arrays affect the results?
If you want to show the benchmark results, pls consider such conditions.

Thanks,
Koichi

----------------------------------------
Feature #15380: faster method lookup for Array#all? #none?  #one?
https://bugs.ruby-lang.org/issues/15380#change-75402

* Author: fursich (Onishi Koji)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
## summary

This PR proposes Array-specific implementations for `#all?` , `#none?` and `#one?` to enable faster method lookup.

Before this patch `Array#all?` was not implemented in Array class, so alternatively, `Enumerable#all?` was used each time the method is called.

On the other hand, `#any?` has its own method entry in Array class for faster method calls.

This patch provides above three methods with Array-specific implementations that are equivalent to what `Array#any?` has.


https://github.com/ruby/ruby/pull/2041



## benchmark


~~~ text
**********************************************************************************
benchmarking Array#all?
**********************************************************************************

Calculating -------------------------------------
    Array#all? (new)          421.298 i/s -      1.000k times in 2.373616s (2.37ms/i)
    Array#all? (old)          335.364 i/s -      1.000k times in 2.981838s (2.98ms/i)

Comparison:
    Array#all? (new):       421.3 i/s
    Array#all? (old):       335.4 i/s - 1.26x  slower

<running with --jit>
Calculating -------------------------------------
    Array#all? (new)                244.929 i/s -      1.000k times in 4.082823s (4.08ms/i)
    Array#all? (old)                210.354 i/s -      1.000k times in 4.753895s (4.75ms/i)

Comparison:
    Array#all? (new):       244.9 i/s
    Array#all? (old):       210.4 i/s - 1.16x  slower
~~~

Attached benchmark shows the full benchmark results:

https://gist.github.com/fursich/1d1bad353ddc2f4b510b34e3191fd302


Each method gets approx. 10-20% faster with repeated calls.
It only impacts on method lookup (not execution itself), but at least it should make` Array#all?` work as just efficiently as `Array#any?` does.


## estimate of impact

Just to provide a rough picture on how frequently these methods are used in real world app, here shows a quick-and-dirty investigations I did with [rails](https://github.com/rails/rails) (using its latest master as of Dec 5):

~~~ text
rails (master)$ git grep '\.all?' | wc -l
      80
rails (master)$ git grep '\.one?' | wc -l
      13
rails (master)$ git grep '\.none?' | wc -l
      25
~~~

while
~~~ text
rails (master)$ git grep '\.any?' | wc -l
~~~

(* the result includes non-Array method. the intention here is just to give rough estimate on how frequently these methods are used compared with each other)

It's probably fair to say the use of the three methods (118 lines in total here) are *not* ignorably rare compared to `#all?`


## motivation behind it

In developing Ruby apps we encounter (often non essential) discussion around 'which method call is faster?', 'should we use this method for efficiency?'.

As Ruby lover I really hope to pick methods based on pure readability and Ruby-ness, 

Hopefully it helps Ruby become faster even at slightest level :)




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:90298] [Ruby trunk Feature#15380] faster method lookup for Array#all? #none? #one?
       [not found] <redmine.issue-15380.20181205042657@ruby-lang.org>
  2018-12-05  4:26 ` [ruby-core:90294] [Ruby trunk Feature#15380] faster method lookup for Array#all? #none? #one? fursich0
  2018-12-05  4:55 ` [ruby-core:90295] " ko1
@ 2018-12-05  6:23 ` shevegen
  2018-12-05  6:54 ` [ruby-core:90299] " hanmac
  2018-12-05 22:11 ` [ruby-core:90330] " hanmac
  4 siblings, 0 replies; 5+ messages in thread
From: shevegen @ 2018-12-05  6:23 UTC (permalink / raw)
  To: ruby-core

Issue #15380 has been updated by shevegen (Robert A. Heiler).


While I agree with Koichi in regards to benchmarks and more code 
meaning more maintenance work (naturally), I think it should still
be considered for the trade off being potentially worth it. If there
is time for discussion at the next developer meeting perhaps matz
could be asked.

----------------------------------------
Feature #15380: faster method lookup for Array#all? #none?  #one?
https://bugs.ruby-lang.org/issues/15380#change-75405

* Author: fursich (Onishi Koji)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
## summary

This PR proposes Array-specific implementations for `#all?` , `#none?` and `#one?` to enable faster method lookup.

Before this patch `Array#all?` was not implemented in Array class, so alternatively, `Enumerable#all?` was used each time the method is called.

On the other hand, `#any?` has its own method entry in Array class for faster method calls.

This patch provides above three methods with Array-specific implementations that are equivalent to what `Array#any?` has.


https://github.com/ruby/ruby/pull/2041



## benchmark


~~~ text
**********************************************************************************
benchmarking Array#all?
**********************************************************************************

Calculating -------------------------------------
    Array#all? (new)          421.298 i/s -      1.000k times in 2.373616s (2.37ms/i)
    Array#all? (old)          335.364 i/s -      1.000k times in 2.981838s (2.98ms/i)

Comparison:
    Array#all? (new):       421.3 i/s
    Array#all? (old):       335.4 i/s - 1.26x  slower

<running with --jit>
Calculating -------------------------------------
    Array#all? (new)                244.929 i/s -      1.000k times in 4.082823s (4.08ms/i)
    Array#all? (old)                210.354 i/s -      1.000k times in 4.753895s (4.75ms/i)

Comparison:
    Array#all? (new):       244.9 i/s
    Array#all? (old):       210.4 i/s - 1.16x  slower
~~~

Attached benchmark shows the full benchmark results:

https://gist.github.com/fursich/1d1bad353ddc2f4b510b34e3191fd302


Each method gets approx. 10-20% faster with repeated calls.
It only impacts on method lookup (not execution itself), but at least it should make` Array#all?` work as just efficiently as `Array#any?` does.


## estimate of impact

Just to provide a rough picture on how frequently these methods are used in real world app, here shows a quick-and-dirty investigations I did with [rails](https://github.com/rails/rails) (using its latest master as of Dec 5):

~~~ text
rails (master)$ git grep '\.all?' | wc -l
      80
rails (master)$ git grep '\.one?' | wc -l
      13
rails (master)$ git grep '\.none?' | wc -l
      25
~~~

while
~~~ text
rails (master)$ git grep '\.any?' | wc -l
~~~

(* the result includes non-Array method. the intention here is just to give rough estimate on how frequently these methods are used compared with each other)

It's probably fair to say the use of the three methods (118 lines in total here) are *not* ignorably rare compared to `#all?`


## motivation behind it

In developing Ruby apps we encounter (often non essential) discussion around 'which method call is faster?', 'should we use this method for efficiency?'.

As Ruby lover I really hope to pick methods based on pure readability and Ruby-ness, 

Hopefully it helps Ruby become faster even at slightest level :)




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:90299] [Ruby trunk Feature#15380] faster method lookup for Array#all? #none? #one?
       [not found] <redmine.issue-15380.20181205042657@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2018-12-05  6:23 ` [ruby-core:90298] " shevegen
@ 2018-12-05  6:54 ` hanmac
  2018-12-05 22:11 ` [ruby-core:90330] " hanmac
  4 siblings, 0 replies; 5+ messages in thread
From: hanmac @ 2018-12-05  6:54 UTC (permalink / raw)
  To: ruby-core

Issue #15380 has been updated by Hanmac (Hans Mackowiak).


Nobu already merged it

----------------------------------------
Feature #15380: faster method lookup for Array#all? #none?  #one?
https://bugs.ruby-lang.org/issues/15380#change-75406

* Author: fursich (Onishi Koji)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
## summary

This PR proposes Array-specific implementations for `#all?` , `#none?` and `#one?` to enable faster method lookup.

Before this patch `Array#all?` was not implemented in Array class, so alternatively, `Enumerable#all?` was used each time the method is called.

On the other hand, `#any?` has its own method entry in Array class for faster method calls.

This patch provides above three methods with Array-specific implementations that are equivalent to what `Array#any?` has.


https://github.com/ruby/ruby/pull/2041



## benchmark


~~~ text
**********************************************************************************
benchmarking Array#all?
**********************************************************************************

Calculating -------------------------------------
    Array#all? (new)          421.298 i/s -      1.000k times in 2.373616s (2.37ms/i)
    Array#all? (old)          335.364 i/s -      1.000k times in 2.981838s (2.98ms/i)

Comparison:
    Array#all? (new):       421.3 i/s
    Array#all? (old):       335.4 i/s - 1.26x  slower

<running with --jit>
Calculating -------------------------------------
    Array#all? (new)                244.929 i/s -      1.000k times in 4.082823s (4.08ms/i)
    Array#all? (old)                210.354 i/s -      1.000k times in 4.753895s (4.75ms/i)

Comparison:
    Array#all? (new):       244.9 i/s
    Array#all? (old):       210.4 i/s - 1.16x  slower
~~~

Attached benchmark shows the full benchmark results:

https://gist.github.com/fursich/1d1bad353ddc2f4b510b34e3191fd302


Each method gets approx. 10-20% faster with repeated calls.
It only impacts on method lookup (not execution itself), but at least it should make` Array#all?` work as just efficiently as `Array#any?` does.


## estimate of impact

Just to provide a rough picture on how frequently these methods are used in real world app, here shows a quick-and-dirty investigations I did with [rails](https://github.com/rails/rails) (using its latest master as of Dec 5):

~~~ text
rails (master)$ git grep '\.all?' | wc -l
      80
rails (master)$ git grep '\.one?' | wc -l
      13
rails (master)$ git grep '\.none?' | wc -l
      25
~~~

while
~~~ text
rails (master)$ git grep '\.any?' | wc -l
~~~

(* the result includes non-Array method. the intention here is just to give rough estimate on how frequently these methods are used compared with each other)

It's probably fair to say the use of the three methods (118 lines in total here) are *not* ignorably rare compared to `#all?`


## motivation behind it

In developing Ruby apps we encounter (often non essential) discussion around 'which method call is faster?', 'should we use this method for efficiency?'.

As Ruby lover I really hope to pick methods based on pure readability and Ruby-ness, 

Hopefully it helps Ruby become faster even at slightest level :)




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:90330] [Ruby trunk Feature#15380] faster method lookup for Array#all? #none? #one?
       [not found] <redmine.issue-15380.20181205042657@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2018-12-05  6:54 ` [ruby-core:90299] " hanmac
@ 2018-12-05 22:11 ` hanmac
  4 siblings, 0 replies; 5+ messages in thread
From: hanmac @ 2018-12-05 22:11 UTC (permalink / raw)
  To: ruby-core

Issue #15380 has been updated by Hanmac (Hans Mackowiak).


@nobu can you close this?

----------------------------------------
Feature #15380: faster method lookup for Array#all? #none?  #one?
https://bugs.ruby-lang.org/issues/15380#change-75438

* Author: fursich (Onishi Koji)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
## summary

This PR proposes Array-specific implementations for `#all?` , `#none?` and `#one?` to enable faster method lookup.

Before this patch `Array#all?` was not implemented in Array class, so alternatively, `Enumerable#all?` was used each time the method is called.

On the other hand, `#any?` has its own method entry in Array class for faster method calls.

This patch provides above three methods with Array-specific implementations that are equivalent to what `Array#any?` has.


https://github.com/ruby/ruby/pull/2041



## benchmark


~~~ text
**********************************************************************************
benchmarking Array#all?
**********************************************************************************

Calculating -------------------------------------
    Array#all? (new)          421.298 i/s -      1.000k times in 2.373616s (2.37ms/i)
    Array#all? (old)          335.364 i/s -      1.000k times in 2.981838s (2.98ms/i)

Comparison:
    Array#all? (new):       421.3 i/s
    Array#all? (old):       335.4 i/s - 1.26x  slower

<running with --jit>
Calculating -------------------------------------
    Array#all? (new)                244.929 i/s -      1.000k times in 4.082823s (4.08ms/i)
    Array#all? (old)                210.354 i/s -      1.000k times in 4.753895s (4.75ms/i)

Comparison:
    Array#all? (new):       244.9 i/s
    Array#all? (old):       210.4 i/s - 1.16x  slower
~~~

Attached benchmark shows the full benchmark results:

https://gist.github.com/fursich/1d1bad353ddc2f4b510b34e3191fd302


Each method gets approx. 10-20% faster with repeated calls.
It only impacts on method lookup (not execution itself), but at least it should make` Array#all?` work as just efficiently as `Array#any?` does.


## estimate of impact

Just to provide a rough picture on how frequently these methods are used in real world app, here shows a quick-and-dirty investigations I did with [rails](https://github.com/rails/rails) (using its latest master as of Dec 5):

~~~ text
rails (master)$ git grep '\.all?' | wc -l
      80
rails (master)$ git grep '\.one?' | wc -l
      13
rails (master)$ git grep '\.none?' | wc -l
      25
~~~

while
~~~ text
rails (master)$ git grep '\.any?' | wc -l
~~~

(* the result includes non-Array method. the intention here is just to give rough estimate on how frequently these methods are used compared with each other)

It's probably fair to say the use of the three methods (118 lines in total here) are *not* ignorably rare compared to `#all?`


## motivation behind it

In developing Ruby apps we encounter (often non essential) discussion around 'which method call is faster?', 'should we use this method for efficiency?'.

As Ruby lover I really hope to pick methods based on pure readability and Ruby-ness, 

Hopefully it helps Ruby become faster even at slightest level :)




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-12-05 22:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-15380.20181205042657@ruby-lang.org>
2018-12-05  4:26 ` [ruby-core:90294] [Ruby trunk Feature#15380] faster method lookup for Array#all? #none? #one? fursich0
2018-12-05  4:55 ` [ruby-core:90295] " ko1
2018-12-05  6:23 ` [ruby-core:90298] " shevegen
2018-12-05  6:54 ` [ruby-core:90299] " hanmac
2018-12-05 22:11 ` [ruby-core:90330] " hanmac

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).