Issue #14739 has been updated by ioquatix (Samuel Williams).
I've made a new branch with the new implementation above.
It shows a slightly improved performance improvement over `libcoro`.
Here is without the PR:
```
^_^ > ./build/bin/ruby ./fiber_benchmark.rb 10000 1000
setup time for 10000 fibers: 0.161763
execution time for 1000 messages: 14.018874
setup time for 10000 fibers: 1.572869
execution time for 1000 messages: 13.778874
setup time for 10000 fibers: 0.917040
execution time for 1000 messages: 13.942525
setup time for 10000 fibers: 1.616929
execution time for 1000 messages: 13.991115
setup time for 10000 fibers: 1.623587
execution time for 1000 messages: 14.281334
```
And here it is with the PR, on macOS (the same system used in previous benchmarks):
```
^_^ > ./build/bin/ruby ./fiber_benchmark.rb 10000 1000
setup time for 10000 fibers: 0.160637
execution time for 1000 messages: 6.009332
setup time for 10000 fibers: 0.244175
execution time for 1000 messages: 6.246711
setup time for 10000 fibers: 0.242718
execution time for 1000 messages: 6.142166
setup time for 10000 fibers: 0.233410
execution time for 1000 messages: 5.994752
setup time for 10000 fibers: 0.288830
execution time for 1000 messages: 6.216617
```
Performance is about 2~2.5x faster depending on your analysis. Both creation and execution time is improved. But remember this is micro-benchmark.
I was also interested in mjit performance:
Without PR, enabled mjit:
```
^_^ > ./build/bin/ruby --jit ./fiber_benchmark.rb 10000 1000
setup time for 10000 fibers: 0.172145
execution time for 1000 messages: 25.176702
setup time for 10000 fibers: 1.654751
execution time for 1000 messages: 14.729177
setup time for 10000 fibers: 1.016810
execution time for 1000 messages: 15.154141
setup time for 10000 fibers: 1.726305
execution time for 1000 messages: 14.797269
setup time for 10000 fibers: 2.025997
execution time for 1000 messages: 15.124753
```
With PR, enabled mjit:
```
x_x > ./build/bin/ruby --jit ./fiber_benchmark.rb 10000 1000
setup time for 10000 fibers: 0.179744
execution time for 1000 messages: 13.793318
setup time for 10000 fibers: 0.354717
execution time for 1000 messages: 10.664870
setup time for 10000 fibers: 0.308818
execution time for 1000 messages: 6.956352
setup time for 10000 fibers: 0.378568
execution time for 1000 messages: 6.553922
setup time for 10000 fibers: 0.295583
execution time for 1000 messages: 7.274086
```
We can see it still needs a bit of work.
I will try to isolate some interesting results from higher level frameworks.
The updated branch is here: https://github.com/ioquatix/ruby/tree/native-fiber
It only work on Darwin x84 at the moment, because changes to autoconf do not cover all platforms yet. I'll fix this soon.
----------------------------------------
Feature #14739: Improve fiber yield/resume performance
https://bugs.ruby-lang.org/issues/14739#change-72339
* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
I am interested to improve Fiber yield/resume performance.
I've used this library before: http://software.schmorp.de/pkg/libcoro.html and handled millions of HTTP requests using it.
I'd suggest to use that library.
As this is used in many places in Ruby (e.g. enumerable) it could be a big performance win across the board.
Here is a nice summary of what was done for RethinkDB: https://rethinkdb.com/blog/making-coroutines-fast/
Does Ruby currently reuse stacks? This is also a big performance win if it's not being done already.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>