Run reload in a background thread to keep the server responsive#692
Draft
KaanOzkan wants to merge 1 commit intoko/reload-returns-resultfrom
Draft
Run reload in a background thread to keep the server responsive#692KaanOzkan wants to merge 1 commit intoko/reload-returns-resultfrom
KaanOzkan wants to merge 1 commit intoko/reload-returns-resultfrom
Conversation
On large Rails apps (e.g., Bourgeois), reload takes 10-20 seconds. During that time, the server can't process any other requests (model info, route info, associations), causing the editor to freeze. Run reload in a background thread and respond immediately. If another reload arrives while one is in progress, mark that a follow-up reload is needed. When the current reload finishes, it checks the flag and reloads once more to pick up changes that arrived mid-reload. This means N rapid reloads result in at most 2 actual reloads. Related: Shopify/team-ruby-dx#1734
a0a95fc to
781c615
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On large Rails apps,
Rails.application.reloader.reload!takes 10-20 seconds. During that time, the server can't process any other requests (model info, route info, associations), causing the editor to freeze completely.This PR runs reload in a background thread and responds to the caller immediately. If another reload request arrives while one is already in progress, it's skipped — the running reload will pick up all file changes anyway (that's how Rails reloader works).
Depends on #691 (reload returns result).
How it works
Trade-off
DSL generation may run against slightly stale state if it starts before the background reload finishes. This is mitigated by the companion Tapioca fix (Don't delete RBIs for missing constants) which preserves existing RBIs when constants are temporarily unavailable.
Testing
Unit tests:
execute("reload")blocked for 2.04sreload!call)End-to-end with real Rails runner:
trigger_reloadresponds instantlyAll 45 existing tests pass.
Related