Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[performance] Change Fiber.yield to not generate a timer event and instead just add itself as the last runnable fiber #3597

Closed
wants to merge 1 commit into from

Conversation

lbguilherme
Copy link
Contributor

This has the same behavior as far as I can tell but without calling into libevent, registering a timer event and waiting for the event to be pulled. This saves some system calls and should be faster.

Benchmark:

class Fiber
  def yield2
    Scheduler.enqueue self
    Scheduler.reschedule
  end
  def self.yield2
    Fiber.current.yield2
  end
end

require "benchmark"
N = 10_000_000

Benchmark.bm do |x|
  x.report("before") do
    spawn do
      N.times {|i| Fiber.yield }
    end

    N.times { Fiber.yield }
  end
  x.report("after") do
    spawn do
      N.times {|i| Fiber.yield2 }
    end

    N.times { Fiber.yield2 }
  end
end

             user     system      total        real
before   3.410000   0.750000   4.160000 (  4.172480)
after    0.520000   0.000000   0.520000 (  0.515067)

@waj
Copy link
Member

waj commented Nov 27, 2016

This is how it was implementer long time ago. The problem with this approach is that you can end in an infinite loop without processing other events (IO or timers). See #1683.

@lbguilherme
Copy link
Contributor Author

Now I see the problem :(

Thanks @waj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants