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

Delayed startup due to slow route generation #4480

Closed
dmarkow opened this issue Nov 1, 2022 · 0 comments · Fixed by #4538
Closed

Delayed startup due to slow route generation #4480

dmarkow opened this issue Nov 1, 2022 · 0 comments · Fixed by #4538

Comments

@dmarkow
Copy link
Contributor

dmarkow commented Nov 1, 2022

What version of Remix are you using?

1.7.4

Steps to Reproduce

See sample repo. This sample app has a patch on the routesConvention.js file to display run time for route generation, as well as a run.js script that generates a bunch of routes and then runs remix routes. Pass an optional number for the number of route sets to create (each set has 111 routes between index/child routes). For example, node run.js 5 will profile with 5 sets of routes (556 routes including the root route). I nested the sample routes under a couple pathless routes as that seems to also decrease the performance.

# Install and run
npm i
npx patch-package
node run.js 5 | head

Expected Behavior

Ideally, performance would decrease linearly as the number of routes increases.

Actual Behavior

Exponential increase in the time it takes to run. On a fairly powerful Mac, 1 set (112 routes) takes 0.042 seconds to compile, 5 sets (556 routes) takes 3.413 seconds, and 10 sets (1,111 routes) takes 26.797 seconds.

$ node run.js 1 | head
Creating sample routes...
defineConventionalRoutes: 0.042s for 112 routes (0.38ms per file)
<Routes>
  <Route file="root.tsx">
    <Route path="0/10/0/0" index file="routes/__a/__b/__c/0/10/0/0/index.js" />
    <Route path="0/10/0/1" index file="routes/__a/__b/__c/0/10/0/1/index.js" />
    <Route path="0/10/1/0" index file="routes/__a/__b/__c/0/10/1/0/index.js" />
    <Route path="0/10/1/1" index file="routes/__a/__b/__c/0/10/1/1/index.js" />
    <Route path="0/10/2/0" index file="routes/__a/__b/__c/0/10/2/0/index.js" />
    <Route path="0/10/2/1" index file="routes/__a/__b/__c/0/10/2/1/index.js" />

$ node run.js 5 | head
Creating sample routes...
defineConventionalRoutes: 3.413s for 556 routes (6.14ms per file)
<Routes>
  <Route file="root.tsx">
    <Route path="0/10/0/0" index file="routes/__a/__b/__c/0/10/0/0/index.js" />
    <Route path="0/10/0/1" index file="routes/__a/__b/__c/0/10/0/1/index.js" />
    <Route path="0/10/1/0" index file="routes/__a/__b/__c/0/10/1/0/index.js" />
    <Route path="0/10/1/1" index file="routes/__a/__b/__c/0/10/1/1/index.js" />
    <Route path="0/10/2/0" index file="routes/__a/__b/__c/0/10/2/0/index.js" />
    <Route path="0/10/2/1" index file="routes/__a/__b/__c/0/10/2/1/index.js" />

$ node run.js 10 | head
Creating sample routes...
defineConventionalRoutes: 26.797s for 1111 routes (24.12ms per file)
<Routes>
  <Route file="root.tsx">
    <Route path="0/10/0/0" index file="routes/__a/__b/__c/0/10/0/0/index.js" />
    <Route path="0/10/0/1" index file="routes/__a/__b/__c/0/10/0/1/index.js" />
    <Route path="0/10/1/0" index file="routes/__a/__b/__c/0/10/1/0/index.js" />
    <Route path="0/10/1/1" index file="routes/__a/__b/__c/0/10/1/1/index.js" />
    <Route path="0/10/2/0" index file="routes/__a/__b/__c/0/10/2/0/index.js" />
    <Route path="0/10/2/1" index file="routes/__a/__b/__c/0/10/2/1/index.js" />

In my real world app, it's taking around 10-15 seconds to load around 700 routes (this test repo may be operating more efficiently due to short folder/route names versus the longer route paths used in my actual app). Running npm run dev has a significant delay where it seems like nothing is happening, then after 10-15 seconds the "Watching Remix app in development mode..." message finally shows up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant