Reimplement Timeout.timeout with a single thread and a Queue#15
Reimplement Timeout.timeout with a single thread and a Queue#15hsbt merged 5 commits intoruby:masterfrom
Conversation
|
For some reason it seems I can't push to |
ea02069 to
64c91e6
Compare
|
I can now push again to this PR. JRuby already has this behavior, so it passes the test. |
64c91e6 to
bda299c
Compare
|
This implementation appears to be the slowest at this point, but I think there's a bug or leak of some kind. My naive benchmark of repeatedly timing out an empty block gets progressively slower over time: |
|
The effect is even more pronounced on TruffleRuby 21.3: |
|
Indeed. |
|
Performance: require 'timeout'
require 'benchmark/ips'
Benchmark.ips do |x|
x.report("timeout") do
Timeout.timeout(1, Timeout::Error) {}
end
endIt seems a clear win for all on this benchmark. |
|
The results above are with an explicit Still a clear gain for all. |
* This is needed by Timeout.timeout in ruby/timeout#15 * Reuse Kernel#raise for convenience to both call #build_exception_for_raise and set the backtrace and print if $DEBUG.
2b8a2d4 to
306ebe0
Compare
306ebe0 to
74add5e
Compare
|
All green now. |
* So it is trivially correct. * Performance seems the same overall.
* It's already checked inside #interrupt.
ecbe290 to
5f43254
Compare
|
Perf on JRuby seems to be best with this implementation. I vote to merge and release this change. |
|
Anything holding this up? I've got folks at RailsConf interested in trying out JRuby 9.4 but I don't want them to have a poor experience due to the multi-thread timeout. |
* This is needed by Timeout.timeout in ruby/timeout#15 * Reuse Kernel#raise for convenience to both call #build_exception_for_raise and set the backtrace and print if $DEBUG.
* This is needed by Timeout.timeout in ruby/timeout#15 * Reuse Kernel#raise for convenience to both call #build_exception_for_raise and set the backtrace and print if $DEBUG.
| fail-fast: false | ||
| matrix: | ||
| ruby: [ '3.0', 2.7, 2.6, 2.5, 2.4, head ] | ||
| ruby: [ '3.0', 2.7, 2.6, 2.5, 2.4, head, jruby, truffleruby-head ] |
* For timeout I basically rewrote the implementation in ruby/timeout#15 and acted as a maintainer since then by reviewing PRs and replying to issues. * I always had an interest about the benchmark stdlib and did significant contributions to it, notably 979ec8d.
Related to discussion in #14.
I wrote all of the changed code myself, so there is no worry about relicensing or so (notably the rubysl-timeout repository which had the Rubinius
timeout.rbno longer exists).This seems to work great.
I'd like a review, and I'll self-review in more details later.