Project

General

Profile

Actions

Feature #15592

open

mode where "autoload" behaves like an immediate "require"

Added by akr (Akira Tanaka) almost 6 years ago. Updated over 2 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:91454]

Description

How about a feature to switch "autoload" behavior to "require" immediately.

autoload is a feature for lazy loading.

matz dislikes autoload as [Feature #5653].
I heard that he dislikes class (and other) definitions at arbitrary timing.
I agree that eager loading is safer than lazy loading.

However, lazy loading realize shorter loading time and
it makes development cycle shorter.
It is more important for larger applications as Eregon said in
https://bugs.ruby-lang.org/issues/5653#note-39 .
It is especially important when library loading causes I/O (code generation from DB schema).

These two, safety of eager loading and easier development of lazy loading, conflicts.
But if we can distinguish production mode and development mode,
we can enjoy both benefits.

So, I propose a feature to select autoload behavior from two modes:

  • autoload behaves as lazy loading as now in development mode
  • autoload behaves as eager loading (immediately invokes "require") in production mode.

There are several idea to switch the mode:

  • $AUTOLOAD_MODE = :eager or :lazy
  • RubyVM.autoload_mode = :eager or :lazy
  • ObjectSpace.autoload_mode = :eager or lazy

I'm not sure there is a good enough one in above list, though.


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #5653: "I strongly discourage the use of autoload in any standard libraries" (Re: autoload will be dead)Closedmatz (Yukihiro Matsumoto)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0