Why are the rails loading so slowly, and what can I do about it?

Rails 3.0 is a serious dog. I have been developing on Rails for 5 years and it has never been slower to launch. In particular, tests are forever saved for loading on the upper MacBook with SSDs, so iterative cycles suffer a lot. I need to read an article every time I start a test. This is crazy, not mobile. I could also compile.

This is the main motivation for me to finally switch from Rails - when I have a chance.

If anyone has a solution, suggest it. I know that many people suffer from this problem.

I do not use rspec - I know that there is a solution to help with tests for rspec.

I use quick_require and rails-dev-boost, but have no significant effect.

I'm on Ruby 1.9.2 and should be. One fairly simple controller test takes 26 seconds on a dual-core 2.1 GHz MacBook Air with 4 GB of RAM and an SSD! Why!?

+49
ruby-on-rails ruby-on-rails-3
Apr 21 '11 at 1:13
source share
9 answers

To quote Yehuda Katz:

There are things that C requires a code of 1.9, which slows down. One such example is re-checking $ LOAD_PATH to make sure that it expands with every request. This is what should be considered by the ruby ​​core. Ill open a redmine ticket if it is already gone.

I am also experiencing this problem, and the $ LOAD_PATH problem seems to be a potential cause. Lets hope that it will be fixed soon.

That sounds to me like you just need to suffer through this, and hopefully this will be fixed in Ruby 1.9.3.

+8
May 22 '11 at 14:28
source share

Check out spork . It essentially launches a small server, which starts the download, and then waits for test runs, allowing you to download once, and then check this state many times. Sometimes you will have to restart it if you make certain changes to the configuration, but for the most part it allows you to perform fast iterations of the red-green refactor.

+18
Apr 21 2018-11-11T00:
source share

the problem is slow request if you perform minimal profiling, for example

CPUPROFILE=/tmp/my_app_profile RUBYOPT="-r`gem which perftools | tail -1`" ruby -I lib:test test/unit/user_test.rb pprof.rb --text /tmp/my_app_profile 

you probably should see a lot of time spent on the request (another option sees a lot of it in the download, but I think you already know that this is not a problem).

In my window (osx on macbook pro 2011 13 ", with an i5 core and a spinning hard drive), the time is longer in the order of 5 seconds, which is still a lot but more bearable, so maybe it's worth investigating the differences.

How many gems have you installed in your system? Have you tried running tests / loading without packages / rubygems?

+7
May 16 '11 at 7:34
source share

This is a compromise that must pay for the fact that he did not have to write β€œdemand” statements. Rails tries to do the right thing and therefore preloads everything. Basically you have two solutions:

  • Use the preload library that spawns the Rails ( spork ) process
  • Do not use Rails in your tests, extract a domain that you can test outside of Rails (Destroy All Software has one screencast about this). It’s possible to skip loading the Rails .

With all that I said using solution 1). and my package works under half a second (only 70 tests, but the wait for loading Rails is minimal)

+3
May 16 '11 at 7:24 AM
source share

Yes, it is very slow. Oh wait, mvn install in my days java never took less than a minute. With mvn clean install it was crazy slow. Remembering happy days always lifts my spirit.

+1 spork as @hammar offers

combine with guard https://github.com/guard/guard-test to automatically run tests, and you have a combination of killers. Ask him to run his own window and / or screen in it and see how productivity improves :)

Update / Supplement to answer:

Optimization to_s : put a to_s in the paths added to autoload_paths in application.rb, avoiding this to manually do it again and again at runtime. Could save a few seconds ...

+3
May 17 '11 at 18:13
source share

As @ user185374 reports, you pay the require compromise.

I came across an interesting resource to speed up Rails tests without using Rails ... An example is provided using Rspec but you will have logic.

Here's how the writer sums it up:

I can't tell you what it means to run all of my 150+ specs in 2 seconds. I think this is a little extra work, but it's worth the effort!

Another solution I just found: Hydra parallel testing:

http://logicalfriday.com/2011/05/18/faster-rails-tests-with-hydra/

+2
May 21 '11 at 15:16
source share

This is a known issue, especially on Ruby 1.9.2.

The good news is that the patch is to speed up the launch of Ruby ( require ).

+2
Jun 30 2018-11-15T00:
source share

Good news. Rails starts within a reasonable amount of time after upgrading to Ruby 1.9.3.

0
Apr 17 '12 at 2:10
source share

Take a look at zeus gem .

This should significantly speed up the process.

0
Aug 10 '15 at 14:49
source share



All Articles