From: ko1@... Date: 2021-01-05T09:07:18+00:00 Subject: [ruby-core:101932] [Ruby master Bug#17497] Ractor performance issue Issue #17497 has been updated by ko1 (Koichi Sasada). with perf (with `--call-graph dwarf`) option, I may figure out the big difference: ``` master: - 63.72% 6.23% miniruby miniruby [.] inject_op_i - 57.49% inject_op_i - 55.13% rb_funcallv_public - rb_call (inlined) - 26.94% rb_call0 + 17.69% rb_callable_method_entry_with_refinements + 3.30% stack_check (inlined) 2.75% rb_method_call_status (inlined) + 1.03% rb_class_of (inlined) - 25.91% rb_vm_call0 - vm_call0_body (inlined) + 13.27% vm_call0_cfunc (inlined) 0.50% vm_passed_block_handler (inlined) 0.50% rb_vm_check_ints (inlined) 1.21% rb_current_execution_context (inlined) 0.59% rb_vm_call_kw 1.73% rb_sym2id 0.63% rb_enum_values_pack + 4.38% _start + 0.53% 0x564cbc05b517 ruby 2.7: - 46.93% 9.09% miniruby miniruby [.] inject_op_i - 37.85% inject_op_i - 34.18% rb_funcallv_with_cc - 23.15% vm_call0_body + 17.07% vm_call0_cfunc (inlined) 0.81% rb_vm_check_ints (inlined) + 4.22% vm_search_method (inlined) 2.94% rb_sym2id 0.73% rb_enum_values_pack + 8.13% _start ``` ---------------------------------------- Bug #17497: Ractor performance issue https://bugs.ruby-lang.org/issues/17497#change-89780 * Author: marcandre (Marc-Andre Lafortune) * Status: Open * Priority: Normal * Assignee: ko1 (Koichi Sasada) * ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin18] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- There's a strange performance issue with Ractor (at least on MacOS, didn't run on other OS). I ran a benchmark doing 3 different types of work: * "fib": method calls (naive fibonacci calculation) * "cpu": `(0...1000).inject(:+)` * "sleep": call `sleep` I get the kind of results I was excepting for the `fib` and for sleeping, but the results for the "cpu" workload show a problem. It is so slow that my pure Ruby backport (using Threads) is 65x faster ���� on my Mac Pro (despite having 6 cores). Expected results would be 6x slower, so in that case Ractor is 400x slower than it should ���� On my MacBook (2 cores) the results are not as bad, the `cpu` workload is 3x faster with my pure-Ruby backport (only) instead of ~2x slower, so the factor is 6x too slow. ``` $ gem install backports Successfully installed backports-3.20.0 1 gem installed $ ruby ractor_test.rb :267: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues. fib: 110 ms | cpu: 22900 ms | sleep: 206 ms $ B=t ruby ractor_test.rb Using pure Ruby implementation fib: 652 ms | cpu: 337 ms | sleep: 209 ms ``` Notice the `sleep` run takes similar time, which is good, and `fib` is ~6x faster on my 6-core CPU (and ~2x faster on my 2-core MacBook), again that's good as the pure ruby version uses Threads and thus runs with a single GVL. The `cpu` version is the problem. Script is here: https://gist.github.com/marcandre/bfed626e538a3d0fc7cad38dc026cf0e -- https://bugs.ruby-lang.org/ Unsubscribe: