Speeding up gem on OS X Leopard
Update: gem has changed for the better, and this is no longer necessary. Go ahead and gem update --system.
After upgrading to Leopard from Tiger, I noticed that certain network operations for some processes suddenly took forever. Most noticeably, when gem would update metadata. And I’m not the only one.
It’s not so bad anymore, and all I had to do was grab something from the standard library.
In gem (mine’s at /usr/local/bin/gem), add this line before any other code:
require 'resolv-replace'
Done. Seriously. gem will work much faster. Not as fast as you remember from Tiger, but getting there.
Discussions I’ve had suggest that Leopard isn’t caching DNS requests from certain processes, and letting Ruby handle that itself gets around this.
Update: Here’s the current state of my /usr/local/bin/gem:
#!/usr/local/bin/ruby
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
# See LICENSE.txt for permissions.
#++
require 'resolv-replace'
require 'rubygems'
require 'rubygems/gem_runner'
required_version = Gem::Requirement.new ">= 1.8.2"
unless required_version.satisfied_by? Gem::Version.new(RUBY_VERSION) then
abort "Expected Ruby Version #{required_version}, was #{RUBY_VERSION}"
end
# We need to preserve the original ARGV to use for passing gem options
# to source gems. If there is a -- in the line, strip all options after
# it...its for the source building process.
args = !ARGV.include?("--") ? ARGV.clone : ARGV[0...ARGV.index("--")]
Gem::GemRunner.new.run args
Flinn said,
March 19, 2008 @ 2:16 pm
After adding that here’s what I get:
$ sudo gem update
Updating installed gems…
ERROR: While executing gem … (Gem::RemoteFetcher::FetchError)
Hostname not known: gems.rubyforge.org (SocketError)
getting size of http://gems.rubyforge.org/Marshal.4.8
Jonno said,
March 19, 2008 @ 2:43 pm
Works well. Thanks
Stan said,
March 19, 2008 @ 5:16 pm
If you think gem is bad, give script/plugin a whirl. Arggggggg! Slow as molasses. Would the same patch speed it up?
Aaron Batalion said,
March 19, 2008 @ 7:29 pm
I got around this issue with the following:
$ cat ~/.gemrc
gem: –no-update-sources –no-ri –no-rdoc
Flinn said,
March 19, 2008 @ 8:27 pm
Doesn’t seem to work for me:
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
# See LICENSE.txt for permissions.
#++
require 'resolv-replace'
require 'rubygems'
...
Stan said,
March 20, 2008 @ 11:40 am
One more thing. I noticed that all of my internet activity was compromised since updating to Leopard so in addition to exploring articles like this, I also l googled Leopard dns cache postings. I eventually stumbled upon postings that suggested that some ISPs are having problems with their DNS servers due to some changes in IP addresses that they hadn’t implemented yet. Many people suggested switching DNS lookups to OpenDNS. OpenDNS is a free DNS service that claims to provide superior DNS lookups. I gave it a try. The performance of all of my internet searches have significantly improved: gems, plugins, Safari, and Firefox. Check it out.
giles bowkett said,
March 20, 2008 @ 11:51 am
Here’s my ghetto hack: http://s3.amazonaws.com/giles/gems_hack_031908/metadata.gif
E. James O'Kelly said,
March 27, 2008 @ 6:34 pm
You are my new hero! This has been pissing me off for a long time now and I have had to resource to downloading gems and installing them locally, which obviously keeps me from updating existing gems.
To find where your gem script is just do a:
which gem