-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Officially support requiring subparts of concurrent-ruby, e.g., require 'concurrent/map' #934
Comments
I notice adding a runtime dependency on Zeitwerk would require breaking
|
That's true, it might be worth adapting that goal though. |
The problem with this idea is that you can easily end up in a situation where one of the concurrent-ruby classes is only used at runtime. Assuming we're talking about a web application, that means the code will be loaded during the first request cycle that uses it, defeating Copy on Write (for most MRI setups) and also busting the global constant cache (big deal for MRI right now, may change in the future). |
If the goal is to optimize COW fork / avoiding autoloading then one should eagerly load, Zeitwerk has a mode for that: https://github.com/fxn/zeitwerk#global-eager-load |
My point is that right now, when you use one of the concurrent-ruby component, you explictly require it, which means you get both:
If you were to migrate to Zeitwerk, you'd have to choose between loading things that are not used, vs maybe not eagerloading things. So I don't think autoloading (be it with zeitwerk or Kernel#autoload) is a good fit for libraries such as |
That's what is explicitly not supported currently: https://github.com/ruby-concurrency/concurrent-ruby#usage In my understanding Zeitwerk solves this issue of loading the necessary dependencies automatically. I think the autoloading/constant invalidation/COW issue is far more general, it seems very likely an application will load extra classes on the first request, unless everything is eager loaded. |
Well, somehow it works because I've never seen any code requiring it all.
What Zeitwerk does it to automatically setup |
I guess a common way to support specific |
I started work on this: #980 Currently:
A cycle: Synchronization::Object (synchronization/object.rb) -> AtomicReference (through generated code for #initialize) |
Currently, concurrent-ruby loads every file of the gem eagerly (like most gems actually, this is more reliable than manually setting up
autoload
s everywhere which is error-prone).It would be nice footprint-wise if only the files needed for the usages are loaded.
The best way to do that seems to adopt https://github.com/fxn/zeitwerk.
That would mean dropping support for Ruby < 2.5, which should probably be discussed in a separate issue first.
From a discussion with Petr and @chrisseaton.
The text was updated successfully, but these errors were encountered: