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

activesupport on ruby 2.6 | using 1.hour in step gets slow #34888

Closed
artisr opened this issue Jan 7, 2019 · 5 comments · Fixed by #34899

Comments

@artisr
Copy link

@artisr artisr commented Jan 7, 2019

Steps to reproduce

use ruby 2.6 & activesupport 5.2.2

(1...72000).step(1.hour).each { |x| puts x }
or any other duration used in step

Expected behavior

be constantly fast

Actual behavior

gets exponentially slower

System configuration

rails 5.2
ruby 2.6

@artisr

This comment has been minimized.

Copy link
Author

@artisr artisr commented Jan 7, 2019

its creating a new duration all the time
https://github.com/rails/rails/blob/5-2-stable/activesupport/lib/active_support/duration.rb#L245

using .step(1.hour.to_i) on duration fixes things, so no biggy, but maybe someone wants to take a peek :)

@eileencodes

This comment has been minimized.

Copy link
Member

@eileencodes eileencodes commented Jan 7, 2019

Hey @artisr does this happen with Rails 5.2 Ruby 2.5 as well?

@artisr

This comment has been minimized.

Copy link
Author

@artisr artisr commented Jan 7, 2019

@eileencodes no, on ruby 2.5 its instant / no slowdowns.
I guess its because ruby 2.6 has the new Enumerator::ArithmeticSequence

Just to make it clear, its not limited to 1.hour its to any duration used in step

@brian-kephart

This comment has been minimized.

Copy link
Contributor

@brian-kephart brian-kephart commented Jan 8, 2019

I'm experiencing this issue as well, with the same versions.

@brian-kephart

This comment has been minimized.

Copy link
Contributor

@brian-kephart brian-kephart commented Jan 8, 2019

My code uses a range of times, like this:

(Time.parse('10am').to_i..Time.parse('9pm').to_i).step(30.minutes).each do |time|
  puts time
end

The symptoms are all the same as @artisr, I just wanted to point out the issue occurs with multiple range types.

tenderlove added a commit that referenced this issue Jan 8, 2019
This speeds up Range.new(x, y).step(Duration).each { ... }

Fixes #34888
tenderlove added a commit that referenced this issue Jan 8, 2019
This speeds up Range.new(x, y).step(Duration).each { ... }

Fixes #34888
eagletmt added a commit to eagletmt/barbeque that referenced this issue Feb 21, 2019
It fixes significant performance issue with Ruby 2.6 and Rails 5.2.
rails/rails#34888
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.