> About lib being autoloaded or not, it won't be autoloaded because
> autoloading is not thread safe. The only way to make autoloading lib
> threadsafe is if we eagerload *everything* inside lib when the server
> starts, but this can easily lead to confusion and pain since people
> are used to put generators and code specific to environments inside
> lib, causing production to load development or test only specific
> code.
>
> That said, in Rails 3 you will need to require code in lib manually.
> Gems in Rails 2.3 were also allowed to autoload all the code in lib
> and we completely removed that in 3.0. We pretend to remove
> autoloading code from lib in plugins in 3.1 as well. We will only
> autoload code in app/.
Out of curiosity, why is loading the contents of app threadsafe but
not lib? Is it simply a question of the kinds of stuff people tend to
put in lib?
Isn't it like it should be working already?
http://github.com/rails/rails/commit/781d0a9baef77a1d749bc8d7ea1b8e550a13c34a#L2R85
Out of curiosity, why is loading the contents of app threadsafe but not lib? Is it simply a question of the kinds of stuff people tend to put in lib?
> Out of curiosity, why is loading the contents of app threadsafe but not lib?
> Is it simply a question of the kinds of stuff people tend to put in lib?
It is assumed that it is fine to preload everything in app/models etc
because it is happening in 2.3 in production mode. It is even done in
a multiprocess setup so that eg passenger + ree can perform better due
to COW.
But as José mentioned you throw generators in lib and other assorted
stuff Rails just can't blindly execute. It has been long pondered, but
it seems it is the only sensible solution albeit it becomes an
important item in your migration checklist.
BTW, config.autoload_paths means just that, it does not trigger eager
loading as of this writing. So a temporary (?!) easy way to mark that
item done in a multiprocess setup is to add lib to
config.autoload_paths.