socketry / async

An awesome asynchronous event-driven reactor for Ruby.
MIT License
2.15k stars 89 forks source link

Fiber refinement #335

Closed paddor closed 3 months ago

paddor commented 4 months ago

According to the new benchmark script, performance stays the same:

$ ruby monkey_patch_vs_refinement.rb
ruby 3.3.3 (2024-06-12 revision f1c7b6f435) [x86_64-linux]
Warming up --------------------------------------
        monkey patch    26.336k i/100ms
          refinement    27.581k i/100ms
Calculating -------------------------------------
        monkey patch    304.481k (± 8.2%) i/s -    316.032k in   1.045685s
          refinement    303.663k (± 5.6%) i/s -    303.391k in   1.002361s

Comparison:
        monkey patch:   304480.8 i/s
          refinement:   303663.4 i/s - same-ish: difference falls within error

If you'd rather have Fiber#async_task available to anyone, I'm okay with you closing this PR. It just occured to me that a refinement could be used in this case.

ioquatix commented 4 months ago

Is this compatible with JRuby and TruffleRuby? Unfortunately we don't have working tests for those platforms yet. But they are important.

paddor commented 4 months ago

I'm not too familiar with those platforms, but I can test in 2 weeks. On my way to Sweden for vacation right now.

paddor commented 3 months ago

TruffleRuby can bundle but the benchmark script fails. Refinements don't seem to work (at least not when refining Fiber).

With JRuby I can't seem to bundle because of io-event:

async  $ bundle
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Installing io-event 1.6.5 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/roadster/.gem/jruby/3.1.4/gems/io-event-1.6.5/ext
/home/roadster/.rubies/jruby-9.4.8.0/bin/jruby -I
/home/roadster/.rubies/jruby-9.4.8.0/lib/ruby/stdlib extconf.rb

Makefile not found

Gem files will remain installed in
/home/roadster/.gem/jruby/3.1.4/gems/io-event-1.6.5 for inspection.
Results logged to
/home/roadster/.gem/jruby/3.1.4/extensions/universal-java-1.8/3.1.0/io-event-1.6.5/gem_make.out

/home/roadster/.rubies/jruby-9.4.8.0/lib/ruby/stdlib/rubygems/ext/builder.rb:22:in
`make'
/home/roadster/.rubies/jruby-9.4.8.0/lib/ruby/stdlib/rubygems/ext/ext_conf_builder.rb:42:in
`build'
/home/roadster/.rubies/jruby-9.4.8.0/lib/ruby/stdlib/rubygems/ext/builder.rb:171:in
`build_extension'
/home/roadster/.rubies/jruby-9.4.8.0/lib/ruby/stdlib/rubygems/ext/builder.rb:205:in
`block in build_extensions'
  org/jruby/RubyArray.java:1981:in `each'
/home/roadster/.rubies/jruby-9.4.8.0/lib/ruby/stdlib/rubygems/ext/builder.rb:202:in
`build_extensions'
/home/roadster/.rubies/jruby-9.4.8.0/lib/ruby/stdlib/rubygems/installer.rb:843:in
`build_extensions'
/home/roadster/.gem/jruby/3.1.4/gems/bundler-2.5.11/lib/bundler/rubygems_gem_installer.rb:76:in
`build_extensions'
/home/roadster/.gem/jruby/3.1.4/gems/bundler-2.5.11/lib/bundler/rubygems_gem_installer.rb:28:in
`install'
/home/roadster/.gem/jruby/3.1.4/gems/bundler-2.5.11/lib/bundler/source/rubygems.rb:206:in
`install'
/home/roadster/.gem/jruby/3.1.4/gems/bundler-2.5.11/lib/bundler/installer/gem_installer.rb:54:in
`install'
/home/roadster/.gem/jruby/3.1.4/gems/bundler-2.5.11/lib/bundler/installer/gem_installer.rb:16:in
`install_from_spec'
/home/roadster/.gem/jruby/3.1.4/gems/bundler-2.5.11/lib/bundler/installer/parallel_installer.rb:132:in
`do_install'
/home/roadster/.gem/jruby/3.1.4/gems/bundler-2.5.11/lib/bundler/installer/parallel_installer.rb:123:in
`block in worker_pool'
/home/roadster/.gem/jruby/3.1.4/gems/bundler-2.5.11/lib/bundler/worker.rb:62:in
`apply_func'
/home/roadster/.gem/jruby/3.1.4/gems/bundler-2.5.11/lib/bundler/worker.rb:57:in
`block in process_queue'
  org/jruby/RubyKernel.java:1722:in `loop'
/home/roadster/.gem/jruby/3.1.4/gems/bundler-2.5.11/lib/bundler/worker.rb:54:in
`process_queue'
/home/roadster/.gem/jruby/3.1.4/gems/bundler-2.5.11/lib/bundler/worker.rb:90:in
`block in create_threads'

An error occurred while installing io-event (1.6.5), and Bundler cannot
continue.

In gems.rb:
  sus-fixtures-async was resolved to 0.1.3, which depends on
    async was resolved to 2.14.2, which depends on
      io-event

Never mind then.