Rubygems和Bundler:启动缓慢

时间:2011-01-27 21:19:21

标签: ruby rubygems bundler

编辑:Bundler 1.0.9而不是1.0.3有些不同(和更少)的瓶颈。

我非常恼火Rails的启动时间很慢(因为我反复运行测试),所以我试图找出罪魁祸首是使用poor-man's profiling,运行rails console --help(加载所有我的宝石反复,按Ctrl + C,然后查看堆栈跟踪。

除了明显的罪魁祸首如active_support和朋友被加载,有些时候(可能是10%左右),输出看起来与此相似:

$ rails console --help
^C/var/lib/gems/1.9.1/specifications/i18n-0.5.0.gemspec:3:in `new': Interrupt
    from /var/lib/gems/1.9.1/specifications/i18n-0.5.0.gemspec:3:in `load_specification'
    from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:95:in `eval'
    from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:95:in `load_specification'
    from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:153:in `block (2 levels) in load_gems_in'
    from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:152:in `each'
    from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:152:in `block in load_gems_in'
    from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:149:in `reverse_each'
    from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:149:in `load_gems_in'
    from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:345:in `refresh!'
    from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:78:in `from_gems_in'
    from /usr/lib/ruby/1.9.1/rubygems/source_index.rb:58:in `from_installed_gems'
    from /usr/lib/ruby/1.9.1/rubygems.rb:866:in `source_index'
    from /var/lib/gems/1.9.1/gems/bundler-1.0.9/lib/bundler/source.rb:161:in `installed_specs'
    from /var/lib/gems/1.9.1/gems/bundler-1.0.9/lib/bundler/source.rb:151:in `block in fetch_specs'
    from /var/lib/gems/1.9.1/gems/bundler-1.0.9/lib/bundler/index.rb:7:in `build'
    from /var/lib/gems/1.9.1/gems/bundler-1.0.9/lib/bundler/source.rb:150:in `fetch_specs'
    from /var/lib/gems/1.9.1/gems/bundler-1.0.9/lib/bundler/source.rb:65:in `specs'
    from /var/lib/gems/1.9.1/gems/bundler-1.0.9/lib/bundler/definition.rb:159:in `block (2 levels) in index'
    from /var/lib/gems/1.9.1/gems/bundler-1.0.9/lib/bundler/definition.rb:158:in `each'
    from /var/lib/gems/1.9.1/gems/bundler-1.0.9/lib/bundler/definition.rb:158:in `block in index'
    from /var/lib/gems/1.9.1/gems/bundler-1.0.9/lib/bundler/index.rb:7:in `build'
    from /var/lib/gems/1.9.1/gems/bundler-1.0.9/lib/bundler/definition.rb:157:in `index'
    from /var/lib/gems/1.9.1/gems/bundler-1.0.9/lib/bundler/definition.rb:151:in `resolve'
    from /var/lib/gems/1.9.1/gems/bundler-1.0.9/lib/bundler/definition.rb:90:in `specs'
    from /var/lib/gems/1.9.1/gems/bundler-1.0.9/lib/bundler/definition.rb:135:in `specs_for'
    from /var/lib/gems/1.9.1/gems/bundler-1.0.9/lib/bundler/definition.rb:124:in `requested_specs'
    from /var/lib/gems/1.9.1/gems/bundler-1.0.9/lib/bundler/environment.rb:23:in `requested_specs'
    from /var/lib/gems/1.9.1/gems/bundler-1.0.9/lib/bundler/runtime.rb:11:in `setup'
    from /var/lib/gems/1.9.1/gems/bundler-1.0.9/lib/bundler.rb:101:in `setup'
    from /home/jo/src/mercury/config/boot.rb:8:in `<top (required)>'
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from script/rails:5:in `<main>'

所以似乎花了相当长的时间来加载gemspecs。

有什么方法可以加快速度吗?肮脏的黑客也很受欢迎 - 我只想在没有(太多)延迟的情况下运行我的测试套件。

2 个答案:

答案 0 :(得分:2)

你试过spork吗?

答案 1 :(得分:1)

更新到此:如果您使用的是MiniTest,tconsole也非常酷。