# Loading program that uses gems on network share is incredibly slow

**URL:** <https://www.ruby-forum.com/t/loading-program-that-uses-gems-on-network-share-is-incredibly-slow/177614>\
**Category:** Ruby\
**Created:** [October 21, 2009, 1:55am UTC](https://www.ruby-forum.com/t/loading-program-that-uses-gems-on-network-share-is-incredibly-slow/177614 "2009-10-21T01:55:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 21, 2009, 1:55am UTC](https://www.ruby-forum.com/t/loading-program-that-uses-gems-on-network-share-is-incredibly-slow/177614/1 "2009-10-21T01:55:34Z")

</div>

Hi!

Loading program that uses gems on network share is incredibly slow.  
Ruby’s need, due to Rubygems, to search a long list of directories for  
a file to load due to a require can become very tedious on, for  
example, an SMB share. Loading about a hundred files and having a  
$LOAD\_PATH with 20 directories in it equals an insane amount of  
filesystem accesses. Taking network latency into consideration and  
you’ve got unworkable delays at startup.

I was wondering if anyone has had a similar experience and, if so,  
what they did to solve it.

One solution I thought of would be to delay as many of the requires as  
possible, only requiring when the functionality is needed and perhaps  
using autoload.

Another thought I had was to force Rubygems to look in the gem that  
the require is coming from first, perhaps by inspecting  
Kernel#caller. This would lead to a lot fewer directories being  
searched, but would, it seems, require monkeypatching Rubygems.

Is there any way to treat Rubygems more like jars, so that a .gem  
would remain packaged until loaded. This would greatly lessen the  
network traffic and filesystem traversal, in my case.

I don’t want to debate the merits of storing files on a network  
share. Deploying programs on an SMB share at work instead of on each  
user’s computer saves me so much trouble.

Thanks!

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 21, 2009, 2:58am UTC](https://www.ruby-forum.com/t/loading-program-that-uses-gems-on-network-share-is-incredibly-slow/177614/2 "2009-10-21T02:58:13Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Loading program that uses gems on network share is incredibly slow.  
> Ruby’s need, due to Rubygems, to search a long list of directories for  
> a file to load due to a require can become very tedious on, for  
> example, an SMB share.

One option is to avoid using rubygems on the client systems. The  
crown[1] tool I developed collects gem files (including dependencies) in  
a set of lib and bin dirs. Just add those dirs (still on the file share)  
to the client-side RUBYLIB and PATH env vars. Whenever you gem update,  
you would need to recreate the “crown”, as well, but no need to touch  
the clients. This is experimental, of course, so YMMV, especially if  
there is a gem that does something really non-standard to access its  
libs. I’ve been using it in production, but have tested it only on the  
gems I use (web stack with sinatra, thin, sequel).

[1] [GitHub - vjoel/crown: Gather gem lib and bin files under one directory for fast loading and predictable behavior.](http://github.com/vjoel/crown)
