From: shyouhei@ruby-lang.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:100621] [Ruby master Feature#17288] Optimize __send__ call with a literal method name
Date: Wed, 28 Oct 2020 12:32:55 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-88254.20201028123254.482@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17288.20201027083240.482@ruby-lang.org
Issue #17288 has been updated by shyouhei (Shyouhei Urabe).
Eregon (Benoit Daloze) wrote in #note-5:
> Here are the first 1000 .send() usages in gems:
> https://gist.github.com/eregon/21c8f14c478089c1a9295c21661583a9
> 420 of them use a literal Symbol for the first argument.
So? I don’t think we should follow that. If people misunderstand what an OOPL is, we would better not confirm that.
> > Private methods shall not be called at the first place. Period.
>
> It's not as simple, there are many cases where it's reasonable to call private methods.
> For instance things like `Module#{include,prepend,alias_method,define_method}` used to be private, and `Module#remove_const` still is.
They are/were private for reasons. Private methods can be made public later, but that must have been done with really careful considerations by the author. Not by callee people.
> Some gems call their own private methods in tests, which seems fair enough.
Testing private methods! That itself has a bunch of discussions.
But even if we put those topics aside, do we want to optimise such tests? I feel that is very low-priority.
> shyouhei (Shyouhei Urabe) wrote in #note-2:
> > Not against the ability to write `obj.__send__(:method)`, but `obj.method` must be the preferable way and thus must be the fastest thing.
>
> I would think nobody prefers `obj.__send__(:some_method)` to `obj.some_method` if `some_method` is public, so it seems a non-issue to me.
> And anyway `obj.some_method` would always be as fast or faster than `obj.__send__(:some_method)`, never slower (that would be a performance bug).
OK. So the point is wether we want people to call a private method or not. I’m still against that. Encapsulation is a very basic OO principle that Ruby employs. I want that be honoured.
The proposed patch is sending a wrong signal.
----------------------------------------
Feature #17288: Optimize __send__ call with a literal method name
https://bugs.ruby-lang.org/issues/17288#change-88254
* 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/
next prev parent reply other threads:[~2020-10-28 12:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-27 8:32 [ruby-core:100597] [Ruby master Feature#17288] Optimize __send__ call with a literal method name muraken
2020-10-27 18:35 ` [ruby-core:100610] " eregontp
2020-10-28 8:25 ` [ruby-core:100616] " shyouhei
2020-10-28 8:34 ` [ruby-core:100617] " zverok.offline
2020-10-28 9:58 ` [ruby-core:100618] " shyouhei
2020-10-28 10:09 ` [ruby-core:100619] " eregontp
2020-10-28 12:32 ` shyouhei [this message]
2020-10-28 20:48 ` [ruby-core:100624] " marcandre-ruby-core
2020-10-28 20:59 ` [ruby-core:100625] " shevegen
2020-10-29 0:11 ` [ruby-core:100628] " shyouhei
2020-10-29 4:06 ` [ruby-core:100632] " marcandre-ruby-core
2020-10-29 20:12 ` [ruby-core:100660] " eregontp
2020-10-30 0:17 ` [ruby-core:100663] " shyouhei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-88254.20201028123254.482@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).