From: Robert Klemme Date: 2009-06-05T05:45:05+09:00 Subject: Re: Ruby Execution On 04.06.2009 13:40, Mike Stephens wrote: > Brian Candler wrote: >> P.S. If you want to defer loading of classes until when they are used, >> have a look at Kernel#autoload > > Is this the norm? I would have thought it would be a real problem > parsing big frameworks with myriads of classes everytime you want to > make a simple call. Is there a way of keeping a parsed script cached eg > for a web site that is handling hundreds of users doing the same sorts > of things eg browsing product lists? Maybe this additional bit of information helps. When you run a Ruby script the first thing that happens is that it is parsed and translated into an internal binary representation (which one depends on the version and platform used, e.g. ruby 1.9 is differently than 1.8 than JRuby). Only then it is executed, which basically means that the internal representation is interpreted in some way. This is typically pretty efficient compared to the bourne shell approach of doing the parsing line based. I have no insights into JRuby but knowing the JVM it would even be possible that eventually your Ruby code has become machine code when the hot spot engine decides it should compile it. To sum it up: you shouldn't be too concerned about the efficiency of that approach. The issue you are bringing up is rather valid in situations where a largish application (i.e. multiple files) is needed to execute only small interactions (for example when doing classic CGI where a new process is started for each request). Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/