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
RFC: Simplify code reloading by way of fs-events and forking #24981
Comments
REP #1 |
I will look into "strategizing" the current file update checker, and trying to provide a nicer public API for people to implement. |
The main issue I see is that one of the main goals of autoloading is precisely not to have require calls. Just program as if the app was preloaded. This is one of the original motivations of @dhh. Autoloading would be way easier and would match Ruby semantics if |
@fxn I'm not proposing that we make any change about using |
@tenderlove Ah! I interpreted that
meant that child code would use manual |
@fxn right. I don't want to mess with any requires or autloads, only touch our reloading stuff. 😄 |
Platforms that don't support forking generally don't do so because they have parallelism and things like JITs. Isn't Rails (or Ruby) moving in a direction of having or relying on those things?
Yes, views are handled differently, but forking will always bust their caches (evaled templates). |
Possibly MRI will have a JIT in the future. But I don't think that worrying about that is a good reason to block this. Our reloading code is a notorious for headaches and if leveraging tools like Regardless, if we use a strategy pattern, then we can switch in the event that MRI stops supporting |
Another possible challenge I see (at least as things work today) is that routes are loaded during the initialization process, and they may autoload constants. Not saying it cannot be addressed, only adding to the list of gotchas. |
If the main goal is to simplify the code base, doesn't having to keep two implementations defeat that entirely? It should be noted that windows doesn't support fork either, and we're the platform maintainers there. |
@sgrif we're also having problems with deadlocking. On platforms that don't support fork, we can also use |
Seems reasonable for the short term. Would it be possible to for us to maybe look at getting something upstream which could help us accomplish this with threads? It seems like we need some way to approximate run-to-completion semantics, either by being able to block on constant access, or by being able to lock on |
😞 |
This issue has been automatically marked as stale because it has not been commented on for at least three months. |
I believe this is no longer necessary thanks to Zeitwerk. |
Our auto-reload code has always been a pain for maintenance and it's very difficult to understand. I'd like to propose a change to the way we do reloading.
General idea
Run a forking server in development. The parent process can pre-load framework code and gems. Child processes will load application code via normal methods like
require
andautoload
. If our FS monitor detects anything changes and a reload needs to occur, it can send a signal to the parent process and have it reap it's children. The newly born children will load the new code since the parent process didn't have any of the app code loaded.I think we only need to do this for models / controllers (or anything that is in the list in the config). Views don't need to cause a reload because I think we already handle that in a different way.
Challenges
fork
(like JRuby). We should probably make our "code reload" a strategy object, and we can keep the old strategy for other platforms, until we figure out a better solution (or let platform maintainers deal with it).All of the challenges I've thought of don't really seem like blockers to me. Are there any real blockers for doing this? I think it would greatly simplify our reloading system.
The text was updated successfully, but these errors were encountered: