* [ruby-core:97768] [Ruby master Feature#15330] autoload_relative
[not found] <redmine.issue-15330.20181121234341.182@ruby-lang.org>
@ 2020-04-09 19:59 ` brodock
2022-06-19 23:25 ` [ruby-core:109009] " ioquatix (Samuel Williams)
` (2 subsequent siblings)
3 siblings, 0 replies; 4+ messages in thread
From: brodock @ 2020-04-09 19:59 UTC (permalink / raw)
To: ruby-core
Issue #15330 has been updated by brodock (Gabriel Mazetto).
autoload is important for big rails applications, as for things like Rake scripts, being able to load only what is really being used can shave several seconds.
outside of rails world, you are forced to mess with $LOAD_PATH constant which is not fun.
autoload_relative seems to be a logical step here.
----------------------------------------
Feature #15330: autoload_relative
https://bugs.ruby-lang.org/issues/15330#change-84982
* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
I'd like to propose a way to autoload a constant using a relative path.
It could look like:
```
autoload_relative :MyConst, 'models/my_const'
```
My proposal raises two questions:
1) what's the future of `autoload`?
I believe that `autoload` has been there for years, it is used successfully and has no real alternative.
I looked at a sample of 430 top gems (took the 500 top ranked according to Libraries.io, removed those that I failed to process). The number of those gems that appear to use `autoload` at least once is 94 of those (22%).
The number of lines in the code where `autoload` is called can be quite big. The top 5 are:
vagrant: 235
yard: 206
ffaker: 155
aws-sdk: 152
rdoc: 92
This is a minimum bound, as some gems might be using loops, my processing would only detect the one place in the code with `autoload`.
2) are many autoladed paths relative?
My preliminary numbers indicate that of the 94 gems using autoload, at least 75 are autoloading some relative files. That's a lower bound, as my algorithm is pretty crude and will only count the simplest cases as being relative. An example of gem my algorithm does not detect is `yard`, because the author wrote a small method to map the relative paths to global paths (code here: https://github.com/lsegal/yard/blob/master/lib/yard/autoload.rb#L3 )
Of those where my processing detects the relative requires, a vast majority are relative. The average is that 94% of autoloaded files are relative and would benefit from `require_relative`
In summary: I am convinced that `autoload` should remain in Ruby indefinitely. `autoload_relative` would actually be more useful than `autoload`. Even if the future of `autoload` remains uncertain, I would recommend adding `autoload_relative`; if it is ever decided to actually remove `autoload`, removing `autoload_relative` would not really add to the (huge) burden of gem maintainers.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:109009] [Ruby master Feature#15330] autoload_relative
[not found] <redmine.issue-15330.20181121234341.182@ruby-lang.org>
2020-04-09 19:59 ` [ruby-core:97768] [Ruby master Feature#15330] autoload_relative brodock
@ 2022-06-19 23:25 ` ioquatix (Samuel Williams)
2026-02-12 0:22 ` [ruby-core:124771] [Ruby " ioquatix (Samuel Williams) via ruby-core
2026-02-12 8:19 ` [ruby-core:124787] " matz (Yukihiro Matsumoto) via ruby-core
3 siblings, 0 replies; 4+ messages in thread
From: ioquatix (Samuel Williams) @ 2022-06-19 23:25 UTC (permalink / raw)
To: ruby-core
Issue #15330 has been updated by ioquatix (Samuel Williams).
We had a similar discussion here: https://bugs.ruby-lang.org/issues/18841
I don't personally like `autoload`. However, I can see that there is value in it for certain kinds of application code.
Since we have `require` and `require_relative` (which is largely a wrapper around `require`), I agree we should also have `autoload_relative`.
One of the benefits of introducing `autoload_relative` is we can make it more strict by default.
Frankly speaking, there are very few cases where `autoload` should be used, where `autoload_relative` wouldn't be more suitable.
----------------------------------------
Feature #15330: autoload_relative
https://bugs.ruby-lang.org/issues/15330#change-98118
* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
I'd like to propose a way to autoload a constant using a relative path.
It could look like:
```
autoload_relative :MyConst, 'models/my_const'
```
My proposal raises two questions:
1) what's the future of `autoload`?
I believe that `autoload` has been there for years, it is used successfully and has no real alternative.
I looked at a sample of 430 top gems (took the 500 top ranked according to Libraries.io, removed those that I failed to process). The number of those gems that appear to use `autoload` at least once is 94 of those (22%).
The number of lines in the code where `autoload` is called can be quite big. The top 5 are:
vagrant: 235
yard: 206
ffaker: 155
aws-sdk: 152
rdoc: 92
This is a minimum bound, as some gems might be using loops, my processing would only detect the one place in the code with `autoload`.
2) are many autoladed paths relative?
My preliminary numbers indicate that of the 94 gems using autoload, at least 75 are autoloading some relative files. That's a lower bound, as my algorithm is pretty crude and will only count the simplest cases as being relative. An example of gem my algorithm does not detect is `yard`, because the author wrote a small method to map the relative paths to global paths (code here: https://github.com/lsegal/yard/blob/master/lib/yard/autoload.rb#L3 )
Of those where my processing detects the relative requires, a vast majority are relative. The average is that 94% of autoloaded files are relative and would benefit from `require_relative`
In summary: I am convinced that `autoload` should remain in Ruby indefinitely. `autoload_relative` would actually be more useful than `autoload`. Even if the future of `autoload` remains uncertain, I would recommend adding `autoload_relative`; if it is ever decided to actually remove `autoload`, removing `autoload_relative` would not really add to the (huge) burden of gem maintainers.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:124771] [Ruby Feature#15330] autoload_relative
[not found] <redmine.issue-15330.20181121234341.182@ruby-lang.org>
2020-04-09 19:59 ` [ruby-core:97768] [Ruby master Feature#15330] autoload_relative brodock
2022-06-19 23:25 ` [ruby-core:109009] " ioquatix (Samuel Williams)
@ 2026-02-12 0:22 ` ioquatix (Samuel Williams) via ruby-core
2026-02-12 8:19 ` [ruby-core:124787] " matz (Yukihiro Matsumoto) via ruby-core
3 siblings, 0 replies; 4+ messages in thread
From: ioquatix (Samuel Williams) via ruby-core @ 2026-02-12 0:22 UTC (permalink / raw)
To: ruby-core; +Cc: ioquatix (Samuel Williams)
Issue #15330 has been updated by ioquatix (Samuel Williams).
Assignee changed from matz (Yukihiro Matsumoto) to ioquatix (Samuel Williams)
https://github.com/ruby/ruby/pull/16148
----------------------------------------
Feature #15330: autoload_relative
https://bugs.ruby-lang.org/issues/15330#change-116380
* Author: marcandre (Marc-Andre Lafortune)
* Status: Assigned
* Assignee: ioquatix (Samuel Williams)
----------------------------------------
I'd like to propose a way to autoload a constant using a relative path.
It could look like:
```
autoload_relative :MyConst, 'models/my_const'
```
My proposal raises two questions:
1) what's the future of `autoload`?
I believe that `autoload` has been there for years, it is used successfully and has no real alternative.
I looked at a sample of 430 top gems (took the 500 top ranked according to Libraries.io, removed those that I failed to process). The number of those gems that appear to use `autoload` at least once is 94 of those (22%).
The number of lines in the code where `autoload` is called can be quite big. The top 5 are:
vagrant: 235
yard: 206
ffaker: 155
aws-sdk: 152
rdoc: 92
This is a minimum bound, as some gems might be using loops, my processing would only detect the one place in the code with `autoload`.
2) are many autoladed paths relative?
My preliminary numbers indicate that of the 94 gems using autoload, at least 75 are autoloading some relative files. That's a lower bound, as my algorithm is pretty crude and will only count the simplest cases as being relative. An example of gem my algorithm does not detect is `yard`, because the author wrote a small method to map the relative paths to global paths (code here: https://github.com/lsegal/yard/blob/master/lib/yard/autoload.rb#L3 )
Of those where my processing detects the relative requires, a vast majority are relative. The average is that 94% of autoloaded files are relative and would benefit from `require_relative`
In summary: I am convinced that `autoload` should remain in Ruby indefinitely. `autoload_relative` would actually be more useful than `autoload`. Even if the future of `autoload` remains uncertain, I would recommend adding `autoload_relative`; if it is ever decided to actually remove `autoload`, removing `autoload_relative` would not really add to the (huge) burden of gem maintainers.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:124787] [Ruby Feature#15330] autoload_relative
[not found] <redmine.issue-15330.20181121234341.182@ruby-lang.org>
` (2 preceding siblings ...)
2026-02-12 0:22 ` [ruby-core:124771] [Ruby " ioquatix (Samuel Williams) via ruby-core
@ 2026-02-12 8:19 ` matz (Yukihiro Matsumoto) via ruby-core
3 siblings, 0 replies; 4+ messages in thread
From: matz (Yukihiro Matsumoto) via ruby-core @ 2026-02-12 8:19 UTC (permalink / raw)
To: ruby-core; +Cc: matz (Yukihiro Matsumoto)
Issue #15330 has been updated by matz (Yukihiro Matsumoto).
OK, now I accept having `autoload_relative`.
Matz.
----------------------------------------
Feature #15330: autoload_relative
https://bugs.ruby-lang.org/issues/15330#change-116399
* Author: marcandre (Marc-Andre Lafortune)
* Status: Assigned
* Assignee: ioquatix (Samuel Williams)
----------------------------------------
I'd like to propose a way to autoload a constant using a relative path.
It could look like:
```
autoload_relative :MyConst, 'models/my_const'
```
My proposal raises two questions:
1) what's the future of `autoload`?
I believe that `autoload` has been there for years, it is used successfully and has no real alternative.
I looked at a sample of 430 top gems (took the 500 top ranked according to Libraries.io, removed those that I failed to process). The number of those gems that appear to use `autoload` at least once is 94 of those (22%).
The number of lines in the code where `autoload` is called can be quite big. The top 5 are:
vagrant: 235
yard: 206
ffaker: 155
aws-sdk: 152
rdoc: 92
This is a minimum bound, as some gems might be using loops, my processing would only detect the one place in the code with `autoload`.
2) are many autoladed paths relative?
My preliminary numbers indicate that of the 94 gems using autoload, at least 75 are autoloading some relative files. That's a lower bound, as my algorithm is pretty crude and will only count the simplest cases as being relative. An example of gem my algorithm does not detect is `yard`, because the author wrote a small method to map the relative paths to global paths (code here: https://github.com/lsegal/yard/blob/master/lib/yard/autoload.rb#L3 )
Of those where my processing detects the relative requires, a vast majority are relative. The average is that 94% of autoloaded files are relative and would benefit from `require_relative`
In summary: I am convinced that `autoload` should remain in Ruby indefinitely. `autoload_relative` would actually be more useful than `autoload`. Even if the future of `autoload` remains uncertain, I would recommend adding `autoload_relative`; if it is ever decided to actually remove `autoload`, removing `autoload_relative` would not really add to the (huge) burden of gem maintainers.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-02-12 8:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <redmine.issue-15330.20181121234341.182@ruby-lang.org>
2020-04-09 19:59 ` [ruby-core:97768] [Ruby master Feature#15330] autoload_relative brodock
2022-06-19 23:25 ` [ruby-core:109009] " ioquatix (Samuel Williams)
2026-02-12 0:22 ` [ruby-core:124771] [Ruby " ioquatix (Samuel Williams) via ruby-core
2026-02-12 8:19 ` [ruby-core:124787] " matz (Yukihiro Matsumoto) via ruby-core
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).