Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Don't autoload? #45

charlie opened this Issue · 10 comments

5 participants


Posted by Yukihiro Matsumoto (Guest) on 2011-11-19 08:12  

Today, I talked with NaHi about enhancing const_missing to enable
autoload-like feature with nested modules.  But autoload itself has
fundamental flaw under multi-thread environment.  I should have remove
autoload when I added threads to the language (threads came a few
months after autoload).

So I hereby declare the future deprecation of autoload.  Ruby will
keep autoload for a while, since 2.0 should keep compatibility to 1.9.
But you don't expect it will survive further future, e.g. 3.0.

I strongly discourage the use of autoload in any standard libraries.


Development on Ruby 3.0 has not yet started. Matz is quick at changing his opinion (see Module#prepend).

I don't see a threading issue, tbh, as the autoloads should be triggered at load time.


I'm not sure what "should be triggered at load time" means. The docs about Kernel#autoload say:

Registers filename to be loaded (using Kernel::require) the first time that module (which may be a String or a symbol) is accessed.

Last I heard, Kernel#require was not threadsafe. Has that changed? If not, I still question whether deferred non-threadsafe lazy-loading is correct for a core library like rack-protection, whether or not development on Ruby 3.0 has started.


But you won't lazy load anywhere but the main thread.


I guess I don't understand something about autoload/require. There is some guarantee that 2 threads can't/won't call require at the same time?


No. But that does not have anything to do with autoload.


JRuby and Ruby 2.0 autoload is thread-safe and Rubinius autoload is going to be.

@rkh rkh closed this

@rkh can you cite a source for that (particularly Ruby 2)? I've been trying to chase this answer down and don't see evidence for that, especially given what Matz said in the post that started this thread.

@rkh rkh reopened this

I'm also curious about it. Since I started coding with ruby, I see people talking about the autoload not being thread-safe, but I could'nt find a workaround or a official statement about that.



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.