Skip to content
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

Reduce file watching overhead from Rails #555

Merged
merged 1 commit into from
Jan 15, 2025

Conversation

vinistock
Copy link
Member

@vinistock vinistock commented Jan 14, 2025

I noticed that we were spending a lot of time doing file IO operations coming from the listen gem. After some investigation, these appear to be coming from Rails' own file watching mechanisms, which spawn threads that will check if views are being modified to trigger rendering or reloading in the background.

We currently don't have any functionality that depends on views being rendered. Additionally, the LSP already watches files, so even if we wanted to trigger view rendering, the language server would be in a better position to dictate which views to reload.

This PR shuts down view file watching, which eliminates a good chunk of overhead that we were seeing in the Tapioca add-on.

Approach

I initially tried setting config.file_watcher to a no-op implementation, but that doesn't work. The reason is because, by the time we start running server.rb, Rails has already registered the file watchers and its callbacks, so changing the config won't have any real effect.

The approach I took is to clear the file system hooks array from the Action View path registry. Those hooks are the ones that build the file watchers, spawning listen threads. By clearing that array, I can see the overhead disappear in my profiles.

@vinistock vinistock added the enhancement New feature or request label Jan 14, 2025 — with Graphite App
Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@vinistock vinistock requested review from andyw8 and KaanOzkan January 14, 2025 19:54
@vinistock vinistock marked this pull request as ready for review January 14, 2025 19:58
@vinistock vinistock requested a review from a team as a code owner January 14, 2025 19:58
@vinistock vinistock merged commit 27a3728 into main Jan 15, 2025
29 checks passed
@vinistock vinistock deleted the 01-14-reduce_file_watching_overhead_from_rails branch January 15, 2025 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants