Do routes really need to always be reloaded?

Right now, Rails reload routes whenever a code change makes the app reload.

There is an explanation to be found here: rails/finisher.rb at 83a4fa414bc9e5008825f47857fdd80e85c82033 · rails/rails · GitHub. (extracted below)

because if autoloaded constants are cleared we need to reload routes also in case any was used there, as in

mount MailPreview => 'mail_view'

This means routes are also reloaded if i18n is updated, which might not be necessary, but in order to be more precise we need some sort of reloaders dependency support, to be added.

This message is pretty clear, but it’s also 9 years old. Is this still the only reason to do this?

I deal with a pretty big app, loading routes takes 2.5 seconds. Our routes don’t autoload constants. This 2.5s added to every reload feels like a pretty big deal for something we may not need.

I made a very simple monkey-patch to bypass this forced reload, so I’m wondering if there are other problems I could run into? If the answer is no, then I would think that sharing the monkey-patch could be helpful to many teams.

Here is the monkey patch:

module Rails
  class Application
    class RoutesReloader
      def execute

I also wonder if it would be worthwhile to investigate to have a nicer mechanism for improving this situation? For example, detecting if a mount with clearable/autoloadable constant is part of the routes or not. I think feeling fast is important, and this extra work can definitely make Rails feel slower than it needs to be.

Is this really your biggest bottleneck? Sounds unlikely, compared to how much developer time was spent figuring this, granted trivial, monkeypatch. – H

1 Like

Sorry, but I don’t get your point. Took me maybe two hours.

With the monkey-patch, a page that gets reloaded takes 1.5s total, instead of around 4s.

Having 10 developers not spend an extra 2.5 seconds on each reload, breaking the focus/flow, is worth it without a doubt.

Based on Is It Worth the Time?, if I save 2 seconds 10 times a day, i get back 2h after 1 year. This is a low estimate, and then also apply to my colleagues.

Your biggest bottleneck is page loading? I wish I lived in. your world, matey :slight_smile: