Skip to content

Avoid memory dependency between instructions. #8284

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

Merged

Conversation

ioquatix
Copy link
Member

See https://bugs.ruby-lang.org/issues/17263 for more context.

Test program:

#!/usr/bin/env ruby

require 'fiber'

# This program shows how the performance of Fiber.transfer degrades as the fiber
# count increases

def run(num_fibers = 100, repeats = 100000000)
	count = 0

	GC.start
	GC.disable

	fibers = []
	num_fibers.times do
		fibers << Fiber.new { loop { Fiber.yield } }
	end

	# Warmup:
	fibers.each do |f|
		f.resume
	end

	t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)

	while count < repeats
		fibers.each do |f|
			count += 1
			f.resume
		end
	end

	elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0

	puts "fibers: #{num_fibers.to_s.ljust(10)} count: #{count.to_s.ljust(10)} rate: #{(count / elapsed).round(2).to_s.ljust(10)}"
rescue Exception => e
	puts "Stopped at #{count} fibers"
	p e
end

run(*ARGV.map(&:to_i))

It seems to be between 0-5% faster.

@ioquatix ioquatix merged commit 40d774b into ruby:master Aug 25, 2023
@ioquatix ioquatix deleted the amd64-coroutine-transfer-memory-dependency branch August 25, 2023 02:05
hsbt pushed a commit to hsbt/ruby that referenced this pull request May 8, 2024
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.

1 participant