2

Edit: Somewhat different (and fewer) bottlenecks with Bundler 1.0.9 instead of 1.0.3.

I'm terribly annoyed by Rails's slow startup time (since I run tests repeatedly), so I'm trying to find out the culprit is using poor-man's profiling, by running rails console --help (which loads all my gems) repeatedly, hitting Ctrl+C, and looking at the stack trace.

Apart from the obvious culprits like active_support and friends being loaded, some of the time (perhaps 10% or so), the output looks similar to this:

$ 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>'

So it seems that quite some time is spent loading gemspecs.

Is there some way to speed this up? Dirty hacks are appreciated too -- I just want to run my test suite without (so much) delay.

Community
  • 1
  • 1
Jo Liss
  • 30,333
  • 19
  • 121
  • 170
  • 1
    bundler 1.0.3 was really buggy in my opinion. install the latest, i think its 1.0.9. – Jed Schneider Jan 27 '11 at 21:37
  • Ah, it doesn't get updated when I run `bundle update`. Well, of course I guess. So I ran `sudo gem update bundler` and now I have version 1.0.9. Trying again, it looks like it might be marginally faster, and the bottlenecks are now in the `rubygems` package. I'll update this question in a sec. – Jo Liss Jan 27 '11 at 21:51
  • Just an update: Apparently it did speed things up a bit; thanks for the pointer! Now just for the gemspec loading times... – Jo Liss Jan 27 '11 at 22:04

2 Answers2

2

have you tried spork?

Mauricio
  • 5,854
  • 2
  • 28
  • 34
  • Wow -- thanks for answering the question that I *should've* asked. :) I'm loving spork, it solves all my startup time problems. In fact, it doesn't support Ruby 1.9 / minitest, but it's so awesome that I'll migrate all my tests to RSpec just to be able to use spork. :) – Jo Liss Jan 27 '11 at 23:44
1

Update to this: tconsole is really cool too, if you are using MiniTest.

Jo Liss
  • 30,333
  • 19
  • 121
  • 170