[#100309] How to use backport custom field — Jun Aruga <jaruga@...>
Please allow my ignorance.
9 messages
2020/10/06
[#100310] Re: How to use backport custom field
— "NARUSE, Yui" <naruse@...>
2020/10/06
IkJhY2twb3J0IGN1c3RvbSBmaWVsZCIgaXMgb25seSBhdmFpbGFibGUgZm9yIHRpY2tldHMgd2hv
[#100311] Re: How to use backport custom field
— Jun Aruga <jaruga@...>
2020/10/06
On Tue, Oct 6, 2020 at 4:44 PM NARUSE, Yui <[email protected]> wrote:
[#100314] Re: How to use backport custom field
— "NARUSE, Yui" <naruse@...>
2020/10/06
VGhhbmsgeW91IGZvciBjb25maXJtYXRpb24uCkkgY2hlY2tlZCBhZ2FpbiBhbmQgdG8gZWRpdCBi
[#100322] Re: How to use backport custom field
— Jun Aruga <jaruga@...>
2020/10/07
On Tue, Oct 6, 2020 at 7:25 PM NARUSE, Yui <[email protected]> wrote:
[#100326] Re: How to use backport custom field
— "NARUSE, Yui" <naruse@...>
2020/10/07
SSBhZGRlZCB5b3UgdG8gIlJlcG9ydGVyIiByb2xlIGluIHRoZSBwcm9qZWN0CgoyMDIw5bm0MTDm
[#100327] Re: How to use backport custom field
— Jun Aruga <jaruga@...>
2020/10/07
On Wed, Oct 7, 2020 at 1:42 PM NARUSE, Yui <[email protected]> wrote:
[ruby-core:100660] [Ruby master Feature#17288] Optimize __send__ call with a literal method name
From:
eregontp@...
Date:
2020-10-29 20:12:03 UTC
List:
ruby-core #100660
Issue #17288 has been updated by Eregon (Benoit Daloze).
How about a private module instead?
```ruby
class Foo
module Helpers
def self.special # General users should not call or rely on `special`
:special
end
end
private_constant :Helpers
def foo # even from inside our own class...
Helpers.special # this won't work without `send`
end
class Bar
# Bar is a helper class, written by us
def foo
Helpers.special # we want to call special, we need to use `send`
end
end
end
p Foo.new.foo # => :special
p Foo::Bar.new.foo # => :special
p Foo::Helpers.special # => private constant Foo::Helpers referenced (NameError)
```
Refinements seems rather heavy to me for this case, notably it creates extra modules, and makes initial lookups slower (once cached it shouldn't matter much).
For an uncached call (e.g. `refine Object` and many different receivers at some call site), I think the overhead would be noticeable.
Also if the refinements need to be used in multiple files, the module passed to `using` needs to be named, and stored in a private constant.
If done so, there seem little point to `using PrivateHelpers; ...; self.class.foo` vs `PrivateHelpers.foo`, except maybe for instance methods added on existing classes.
But then one could simply use a private method on `Foo` to begin with.
I'm probably biased against refinements because the semantics around refinements + super or eval are fairly messy.
----------------------------------------
Feature #17288: Optimize __send__ call with a literal method name
https://bugs.ruby-lang.org/issues/17288#change-88300
* Author: mrkn (Kenta Murata)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
I made a patch to optimize a `__send__` call with a literal method name. This optimization replaces a `__send__` method call with a `send` instruction. The patch is available in [this pull-request](https://github.com/ruby/ruby/pull/3707).
By this change, the redefined `__send__` method is no longer called when it is called by a literal method name. I guess it is no problem because the following warning message is displayed for a long time.
$ ruby -e 'def __send__; end'
-e:1: warning: redefining `__send__' may cause serious problems
This change makes the optimized case x5~x6 faster. The benchmark result is below:
```
$ make benchmark COMPARE_RUBY="../../ruby/build-o3/ruby" ITEM=vm_send.yml
(snip)
# Iteration per second (i/s)
| |compare-ruby|built-ruby|
|:------------|-----------:|---------:|
|vm_send | 18.536M| 113.778M|
| | -| 6.14x|
|vm_send_var | 18.085M| 16.595M|
| | 1.09x| -|
```
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>