How to optimize Rails/Rspec load time on Windows to the order of seconds? (with or without spork)
Asked Answered
S

3

2

Background:

I am using the RailsInstaller 2 package from Engine Yard, which means Ruby 1.9.2-p290 and Rails 3.1.1, on Windows 7 x64.

Problem:

While attempting the Ruby on Rails Tutorial and after getting autotest and spork to work as intended, it is clear while rspec reported that the tests finished in a few seconds, the actual time consumed is much greater than that and closer to half a minute, a far cry from the split-second response as observed in the screencasts. I am aware that most of that can be attributed to the Rails load time (also evident from amount of time spork spends at the preloading stage), and how JRuby is slower (as compared to Ruby on linux), but 15+s per rspec run on average (with or without spork, taking into account the load times) is quite untenable for TDD. Are there further ways to reduce it to the order of a few seconds, short of switching to Linux?

Edit: is there something wrong with the way I worded this question?

Seat answered 18/1, 2012 at 7:55 Comment(2)
Not an answer to your question, but I tried to use Rails on Windows and it was slow and difficult. Why make it harder than it needs to be? I suggest installing Ubuntu (which can be done on the same machine). I am running single tests in 2.5 sec.Oneal
@BSeven I started off learning Rails on Windows, which I still use for various purposes, then moved to the Linux platforms for serious work. It's always nice to have more choices though.Seat
S
0

This is probably the best at the moment. An identical setup on Windows translates to mere seconds on Linux. I have not tested on Ruby 1.9.3 but that is unlikely to change the situation significantly.

Seat answered 18/2, 2012 at 9:10 Comment(1)
Ruby 1.9.3 is actually much faster.Oneal
E
1

Rails loading time is quite long. As you mentioned this can be a TDD killer.

There are several approaches on how to tackle the problem:

  1. Use Guard to notify fs events and to invoke forking rails using spork, and to invoke rspec tests run on spec file or SUT (subject under test) file change.
  2. Move logic outside of rails dependent classes (controllers, active-record models) and use plain ruby object instead.

I use both approaches. The second approach has many advantages:

  • You can test your classes in isolation with no dependency of rails
  • Tests will run super fast since you are not loading rails, only specific required classes
  • It drives you towards SRP (single responsibility principle) where each class / module has a small part of the whole system
  • It encourages DRY (Don't repeat yourself) - when you have tiny pieces it is easier to reuse them.
  • You are using DI (Dependency Injection) to give context to your small objects which makes them easier to test and reuse.

Must watch:

Evasive answered 20/7, 2012 at 7:59 Comment(1)
thanks for the tips, but now I see this as a lost cause as even on linux, I find myself constantly challenged to optimize (or even minimize) javascript tests, which tend to be really slow and yet take up a good portion of the entire suite. I see Windows as only sufficient for the initial learning curve (up to the conclusion of that tutorial), despite my considerable experience with it.Seat
S
0

This is probably the best at the moment. An identical setup on Windows translates to mere seconds on Linux. I have not tested on Ruby 1.9.3 but that is unlikely to change the situation significantly.

Seat answered 18/2, 2012 at 9:10 Comment(1)
Ruby 1.9.3 is actually much faster.Oneal
A
0

I recently came up with a solution that I haven't seen mentioned elsewhere:

I run Ubuntu in VirtualBox, and have my project's directory configured as a shared folder. This means that the Ubuntu box always sees the latest version of my code, so I can enjoy the linux CLI time, and still keep Windows as my development platform. I've been using this setup for only about a week so far, but I haven't encountered any downsides as of yet.

Apply answered 31/12, 2012 at 14:14 Comment(3)
yes, but strictly speaking this does not address the problem of the speed on native Windows. Using a VM is practical solution, but for another problem (i.e. Windows is slow but I need to run it for some other purpose)Seat
I totally agree. I just wanted to take the opportunity to put this option out there in case someone like me is looking for a practical solution for the problem.Apply
This solution is similar to use Vagrant on windows. Works okay!Successful

© 2022 - 2024 — McMap. All rights reserved.