Bug #17335
closedload gem in ruby 2.6.6 extremely slow
Description
my ruby app starts up extremely slow after I upgrade from ruby version 2.3.1 to 2.7.2. My app does load quite some gems (using "require") at startup. Following code would take 29 secs on my windows 10 PC.
puts Time.now.to_s + ' require starts'
require 'net/ssh'
require 'tk'
require 'tkextlib/tile'
require 'thread'
require 'json'
require 'io/console'
require 'csv'
require 'tkextlib/tcllib/plotchart'
require 'tkextlib/tktable'
require 'socket'
require 'tkextlib/tcllib.rb'
require 'rubyXL'
require 'rubyXL/convenience_methods'
puts Time.now.to_s + ' require ends'
Updated by paulHu (paul hu) over 3 years ago
- Subject changed from load gem in ruby 2.7.2 extremely slow to load gem in ruby 2.6.6 extremely slow
Updated by jeremyevans0 (Jeremy Evans) over 3 years ago
- Status changed from Open to Feedback
Can you please time each of the requires separately to see how much time each is taking, so we can see where the problem is?
Updated by paulHu (paul hu) over 3 years ago
@jeremyevans0 (Jeremy Evans) (Jeremy Evans), thanks for your response. After some experiments, the issue can be boided down to the order of loading gems. If tk is loaded first, then the gems after them would take a long time to load. This becomes extreme with gem rubyXL. Here is the result:
############## first require tk, then rubyXL
t0 = Time.now
require 'tk'
puts Time.now - t0 # 1.35 secs
t0 = Time.now
require 'rubyXL'
puts Time.now - t0 # 58.6 secs
############## first require rubyXL, then tk
t0 = Time.now
require 'rubyXL'
puts Time.now - t0 # 0.28 secs
t0 = Time.now
require 'tk'
puts Time.now - t0 # 2.8 secs
my app use tk as gui. Before I use ruby 2.3.1 and I do not see this issue. After I upgrade to ruby 2.7.2, the issue shows up. And now I downgrade to ruby 2.6.6, the issue is still there.
Updated by paulHu (paul hu) over 3 years ago
could someone please have a look at this?
Updated by jeremyevans0 (Jeremy Evans) over 3 years ago
- Status changed from Feedback to Third Party's Issue
paulHu (paul hu) wrote in #note-4:
could someone please have a look at this?
From your own analysis, the problem seems to be in tk. I can replicate your issue:
$ time ruby -rsequel -rtk -e '1'
0m02.37s real 0m00.34s user 0m00.08s system
$ time ruby -rtk -rsequel -e '1'
0m09.37s real 0m00.19s user 0m00.08s system
However, tk is not in the standard library in any supported version of Ruby. You should file an issue in the ruby-tk bug tracker: https://github.com/ruby/tk/pulls
The simplest workaround would be to require tk after all other libraries.
Updated by paulHu (paul hu) over 3 years ago
thanks Jeremy. I will post the issue in ruby-tk.