16

Ruby 2.0 has been released, see:

http://www.ruby-lang.org/en/news/2013/02/24/ruby-2-0-0-p0-is-released/

What changes to my Rails App/Installation should I anticipate making after upgrading my system to Ruby 2.0?

Brian Petro
  • 1,577
  • 16
  • 32
  • 1
    Seems like there is not a big list of breakages, updating now to see how a live rails app handles it. – Cluster Feb 24 '13 at 19:58
  • 7
    Instead of asking us to foretell any potential snags, go upgrade and try it out. Ask here if you need help solving specific issues. We don't know what version of Rails or which gems you are using. – Substantial Feb 24 '13 at 20:24

2 Answers2

16

So here's what I had to do after upgrading.

Bundler 1.2.x is not compatible, it raises an error saying to upgrade to >= 1.3, which is not yet release. So if you are using RVM, jump into your global gemset for the 2.0 ruby and upgrade to 1.3.pre version until 1.3.0 is released. Also it seems like there's something up with the rubygems api. My bundle install did not use the new API, instead doing the old 'fetch index' method, which of course takes a little bit longer.

Aside from that, my bundle did install cleanly, and my full set of spec tests completed with all OK. I did some timing tests to see how much the rails load time has improved.

# Using 1.9.3-p327

RSpec Time: 24.87s
Wall Time : 34.40s
Load Time :  9.53s

# Using 2.0.0-p0

RSpec Time: 22.49s (90.4%)
Wall Time : 26.89s (78.2%)
Load Time :   4.4s (46.2%)

Obviously the load time for rspec is a little heavier with all of the testing gems, but still over a 50% drop in load time and a 10% drop in test run time is nice.

I did a similar test using rails runner 'puts User.count' which would skip the test bootstrapping.

1.9.3 : 7.27s
2.0.0 : 3.36s (46.2%)

Again, nice drop of over 50% :)

Kind of getting off track here... new toys do that I guess, but it seems like the only change I had to make was upgrading to a pre-release bundler.

Here's another test of different iterators

$ rvm 1.9.3-p327,2.0.0-p0 --verbose do ruby test.rb
ruby-1.9.3-p327: ruby 1.9.3p327 (2012-11-10 revision 37606) [i686-linux] 
       user     system      total        real
for    0.610000   0.000000   0.610000 (  0.607189)
times  0.580000   0.000000   0.580000 (  0.587303)
upto   0.590000   0.000000   0.590000 (  0.585730)
each   0.590000   0.000000   0.590000 (  0.593494)
ruby-2.0.0-p0: ruby 2.0.0p0 (2013-02-24 revision 39474) [i686-linux] 
       user     system      total        real
for    0.590000   0.000000   0.590000 (  0.582743)
times  0.560000   0.000000   0.560000 (  0.565961)
upto   0.560000   0.000000   0.560000 (  0.562400)
each   0.570000   0.000000   0.570000 (  0.573469)

Marginal, about a 4-5% gain.

More interesting is this, calling Object.new 500 million times

1.9.3 : 129.063s
2.0.0 :  97.234s

About a 25% drop in object creation time.

Cluster
  • 5,457
  • 1
  • 25
  • 36
  • "jump into your global gemset for the 2.0", is that the apps gemfile? Or is it something separate? I recently began using RVM. Thanks for the insight! – Brian Petro Feb 24 '13 at 23:24
  • Found it. In .rvm/gemsets. http://stackoverflow.com/questions/4007171/how-do-i-use-rvm-and-create-globally-available-gems – Brian Petro Feb 24 '13 at 23:26
  • 1
    Right, RVM has a global gemset for each installed ruby. It's where it installs bundler, rake and rvm itself. Plus I like to install gems like pry/hub/debugger so they are available everywhere. – Cluster Feb 25 '13 at 05:53
  • @Cluster: Are you using rubies that were both compiled (not prebuilt binaries) by RVM? I'm trying to replicate this test as I'm actually noticing a slow down switching a Rails app to 2.0.0. So I ran an object creation test comparing 1.9.3p392 and 2.0.0p0 and 2.0 actually took over 2x as long as 1.9.3 on the same machine... – jcoleman Feb 27 '13 at 19:17
  • Compiled, RVM didn't have prebuilt for my setup. I'm on 32-bit Ubuntu 12.04 – Cluster Feb 27 '13 at 20:18
  • Is that GCC as the compiler? – jcoleman Feb 27 '13 at 20:57
  • gcc version 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1) – Cluster Feb 28 '13 at 01:33
  • How is 25s -> 22s a 50% drop? – AJcodez Mar 03 '13 at 19:05
  • I was comparing the load time there. I updated to include the load time and added the actual % of 1.9s runtime. – Cluster Mar 03 '13 at 19:24
  • 1
    Although it's nothing to do with the question asked, I love the benchmarks, very interesting. – Mike Campbell Mar 05 '13 at 12:56
6

I started a new project with rails 4 and ruby 2.0. This is how I did it.

First, I set RVM to Ruby 2.0.

Then installed bundler 1.3:

$ gem install bundler

Updated these gems and 'bundle install'.

gem 'rails',     :git => 'git://github.com/rails/rails.git'
gem 'journey',   :git => 'git://github.com/rails/journey.git'
gem 'arel',      :git => 'git://github.com/rails/arel.git'

group :assets do
  gem 'sass-rails',   :git => 'git://github.com/rails/sass-rails.git'
  gem 'coffee-rails', :git => 'git://github.com/rails/coffee-rails.git'
end
Brian Petro
  • 1,577
  • 16
  • 32