From: Xavier Shay Date: 2011-05-03T08:16:57+09:00 Subject: [ruby-core:35976] Re: require performance on 1.9 On 3/05/11 8:37 AM, KOSAKI Motohiro wrote: > Hello, > > 2011/5/1 Xavier Shay: >> Hello, >> I am looking into the performance issues requiring files in 1.9. >> Here is a graph I am trying to fix: >> https://skitch.com/xaviershay/rh64d/tc-load-time >> https://gist.github.com/c8d0d422a9203e1fe492 (after creating 10000 files in >> the `f` dir) >> >> A commit from a few years back [1] adds some behaviour around >> loaded_feature_path. When disabled, the require time in my benchmark is >> halved [2]. There is no test covering this behaviour, and I can't quite >> figure out what it is doing. >> >> It is probably explained in ruby-dev:31932 but I can't read Japanese: >> http://markmail.org/message/d3ef53c63kx2xqkr >> >> Can anyone either translate the above message for me, or provide a test case >> that covers the expected behaviour? > > I don't understand the issue. then I'll make simple translate. :-) > > : As I wrote [ruby-dev:31923], If I wrote > : > :----------------------------------- > :class HOGE; end > :-------------------------------------------- > : > :and, autoload :HOGE, 'hoge.rb' is set on ruby-1.9, require 'hoge.rb' > :makes following exception. > : > :------------------------------------------------------------------------ > :NameError: uninitialized constant HOGE > : from /home/nagai/Ruby-work/hoge.rb:1:in `' > :------------------------------------------------------------------------ > : > :ruby-1.8 works completely. > :I think it's 'autoload' vs 'require' confliction issue. If I use > HOGE.new instead of > :'require', I've seen no issue. > > > Is this related for your issue? I can't make a test case that fails when I continue at load.c:161, skipping an entire code path. I have tried the following, the behaviour was identical with and without my patch. ---- autoload :HOGE, 'hoge.rb' require 'hoge.rb' # no such file to load -- hoge.rb (LoadError) # This is expected since . isn't in load path # Adding . to load path via -I option results in no error --- autoload :HOGE, 'hoge.rb' require './hoge.rb' # Same as above, but fails on line 1 of hoge.rb. I thought this may be the problem but fails on both patched and unpatched rubies. ----- autoload :HOGE, './hoge.rb' require './hoge.rb' # Works ----- In short, I have a patch that eliminates a major code path for requiring that speeds it up twofold, and can't find a failing case for it. See: https://gist.github.com/950154 (now with graph!) I am running this on a moderately sized rails application and seeing a *seven* second improvement in start up time (17s down to 10s). Next weekend I am going to revisit the require code and really try to nut out what it's doing. Xavier > > >> >> Cheers, >> Xavier >> >> P.S. This may or many not be related to this issue: >> http://redmine.ruby-lang.org/issues/show/3924 >> >> [1] >> https://github.com/ruby/ruby/commit/bb1f1c57823758d2450d184ce7c85beb0d538bf0 >> >> [2] add continue; to load.c:161 gives 3s for n=2500 >> >> >