From: marcandre-ruby-core@... Date: 2020-10-29T04:06:13+00:00 Subject: [ruby-core:100632] [Ruby master Feature#17288] Optimize __send__ call with a literal method name Issue #17288 has been updated by marcandre (Marc-Andre Lafortune). shyouhei (Shyouhei Urabe) wrote in #note-9: > @marcandre Here you are: > > [snip brilliant code] 0) I was wrong, I retract what I said. 1) My mind is blown. I have always thought of refinements as a way to safely monkey-patch other people's classes, in particular builtin classes. Never as a way to structure access to our own classes. This can also be very fine-grained if desired. This is brilliant @shyouhei! 2) Goto 1 I made a quick POC with RuboCop to isolate methods that I've always wanted to isolate and the only issues was mocking internal methods: ``` Failure/Error: allow(cop).to receive(:complete_investigation).and_return(cop_report) # does not implement: complete_investigation ``` I'm fine with this, I already try to avoid stub and mocks anyways (10 tests out of 14515 :-) and I'm sure I can find better ways around that. I also wanted to check any performance impact. I couldn't see any (running tests or running RuboCop). Are there any known circumstances where performance would be affected? Are there gems using this technique? Blog posts discussing this? ---------------------------------------- Feature #17288: Optimize __send__ call with a literal method name https://bugs.ruby-lang.org/issues/17288#change-88267 * 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: