DEV: Speed up requests in development mode (PR #12890)

On every request, Rails checks to see whether any ruby code has been changed on the filesystem. The default FileUpdateChecker does this by iterating over every file on the autoload_paths and comparing its modified-time.

In Discourse, our autoload path of /app includes the /app/assets directory, and therefore thousands of non-ruby files (e.g. node_modules). This makes the Dir["/app"] call very slow (>100ms in my case). On my machine, every Rails-handled request spends around 150-200ms in the FileUpdateChecker. This commit introduces a couple of changes to completely eliminate this wasted time:

  • The /app/assets directory is excluded from the file watchers. For me, this cut the time spent in the file_watcher to around 50-100ms

  • Switches our development config to use the EventedFileUpdateChecker, which makes use of the listen gem to subscribe to os-specific notifications of changes. This completely removes the FileUpdateChecker from the critical path

On my machine, topic_list requests now return in around 80ms (previously >200ms). Live code reload still works as it did before


Love it! :racing_car:

This looks very nice, awesome work!