Question

In an effort to speed up my test suite I profiled it and got the following

Total: 1445 samples
     650  45.0%  45.0%     1171  81.0% Kernel#require
     261  18.1%  63.0%      261  18.1% garbage_collector
     47   3.3%  66.3%      168  11.6% Kernel.load
     39   2.7%  69.0%       82   5.7% Module#class_eval
     27   1.9%  70.9%      817  56.5% ActiveSupport::Dependencies::Loadable#load_dependency
     25   1.7%  72.6%       58   4.0% Enumerable#find
     25   1.7%  74.3%       25   1.7% Module#constants
     20   1.4%  75.7%     1171  81.0% Kernel#gem_original_require
     19   1.3%  77.0%       19   1.3% File.file?
     18   1.2%  78.3%      415  28.7% Kernel.require
 .
 .
 .

From this answer Why is Kernel#require taking such a big chunk of my application's resources? I t seems this is expected, but I'm really surprised with the huge number here. Is this really true? Cant we do anything about it?

Était-ce utile?

La solution

There is not much you can do about it because the require step actually builds the AST for your Ruby application - it's "constructed" at runtime as it were. What you need to do though is isolate your profiling to the spots where all of the application loading has been done already (for example, do a couple of dry runs on an action and only then do a profiling run). This way you will exclude the compilation step from your benchmark.

Also make sure you are using 1.9.3 and not 1.9.2 since there was a fix done to speed up require.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top