开发者

Why does Rails take 15+ seconds to load on Ruby 1.9?

开发者 https://www.devze.com 2022-12-27 05:21 出处:网络
On Ruby 1.8.7 a fresh Rails 2.3.5 environment loads in 4.325 seconds, bu开发者_运维知识库t on Ruby 1.9.1p378

On Ruby 1.8.7 a fresh Rails 2.3.5 environment loads in 4.325 seconds, bu开发者_运维知识库t on Ruby 1.9.1p378 it takes 15.701s - does anyone have any ideas why?

This is on a 32-bit single core laptop running Ubuntu.


I'm seeing the same problem as you. On my machine with an SSD, it's 0.7s vs 1.2s for a completely new Rails 2.3.5 project, with REE vs. 1.9.1. On a larger rails project, the difference is more pronounced: It's something like 20s vs. 10s.

This leads me to suspect this is an I/O related issue. Running with a patched require and load:

module Kernel
  alias :load_without_tracing :load
  alias :require_without_tracing :require

  def load(filename, wrap=false)
    puts "loading #{filename}"
    load_without_tracing(filename, wrap)
  end
  def require(string)
    puts "requiring #{string}"
    require_without_tracing(string)
  end
end

says that it's loading a lot of code. This may be what we're seeing. If 1.9.1 pessimized the loading of text files (encodings in strings would be a likely candidate), this would explain the difference in load times we're seeing.

Why it would be a factor of >3 on your machine and <2 on mine, I can only guess, however. Maybe a scenario like this is a good candidate to report to the MRI development mailing list.


Most probably you have some specific issues. I have the same setup 32bit Ubuntu, Rails 2.3.5 and I don't have any problems neither with ruby1.9.1p378 neither with ruby1.9.1p243.

Which application server do you use? Mongrel, Passanger... you can try with a different one than the current and check its startup speed.

0

精彩评论

暂无评论...
验证码 换一张
取 消