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

Build time regression in 2.10.1 #2856

Closed
Aareksio opened this issue Nov 7, 2024 · 11 comments · Fixed by #2857
Closed

Build time regression in 2.10.1 #2856

Aareksio opened this issue Nov 7, 2024 · 11 comments · Fixed by #2857

Comments

@Aareksio
Copy link
Contributor

Aareksio commented Nov 7, 2024

Environment

StackBlitz

------------------------------
- Operating System: Linux
- Node Version:     v18.20.3
- Nitro Version:    2.9.7
- Package Manager:  [email protected]
------------------------------

vs

------------------------------
- Operating System: Linux
- Node Version:     v18.20.3
- Nitro Version:    2.10.3
- Package Manager:  [email protected]
------------------------------

Reproduction

- Go to https://stackblitz.com/edit/github-rppbve
- Run `npm run build`
- Note time it took to execute the command (5s here)

- Go to https://stackblitz.com/github/nitrojs/nitro/tree/main/examples/hello-world
- Run `npm run build`
- Note time it took to execute the command (8s here)

Describe the bug

The discrepancy, while small, is consistent with the minimal reproduction. In my project the total build time doubled from roughly 70-80 seconds to 140-160 seconds. Not sure what more of a reproduction exactly can I provide for this, luckily the change is noticeable even with minimal hello-world example straight from the home page.

One clue perhaps useful to the case, the nuxt prerender takes significantly longer; from ~10s to ~25s to do seemingly the same work; and it does not seem to be related to time spent on actual pages rendered:

ℹ Initializing prerenderer
ℹ Prerendering 1 routes
  ├─ /api/_content/cache.1730940049395.json (225ms)
ℹ Prerendered 1 routes in 10.558 seconds 
[nitro] ℹ Initializing prerenderer
[nitro] ℹ Prerendering 1 routes
[nitro]   ├─ /api/_content/cache.1730933270977.json (98ms)
[nitro] ℹ Prerendered 1 routes in 25.281 seconds

Additional context

No response

Logs

No response

@Aareksio Aareksio changed the title Build regression in 2.10 Build time regression in 2.10 Nov 7, 2024
@antoinezanardi
Copy link

I'm facing the same issue here : the build step for Nitro is now taking 2 minutes instead of the previous 40s :(

Here is a CI job on the new Nitro version : https://github.com/antoinezanardi/werewolves-assistant-web-next/actions/runs/11699055175
Here is a CI job on the old Nitro version : https://github.com/antoinezanardi/werewolves-assistant-web-next/actions/runs/11529961414

You can check the build step to see the build time increase.

@pi0 pi0 added the nuxt label Nov 7, 2024
@pi0
Copy link
Member

pi0 commented Nov 7, 2024

Investigating

@lukaszflorczak
Copy link

lukaszflorczak commented Nov 7, 2024

The same problem. The total time of the build process on Vercel increased to more than 6 minutes after the upgrade (Nuxt 3.14), from about 3:40 before.

Zrzut ekranu 2024-11-7 o 10 55 41 Zrzut ekranu 2024-11-7 o 10 56 15

@pi0
Copy link
Member

pi0 commented Nov 7, 2024

(please use 👍🏼 if you have same issue. please share a runnable reporuction if you can)

@pi0
Copy link
Member

pi0 commented Nov 7, 2024

Two observations inspecting (1) werewolves-assistant-web-next (develop branch)

  • Strangely there are 2 prerender builds (each take ~14s) and then actual build that takes ~170s.
  • There are lots of [plugin unplugin-vue-i18n:directive] Sourcemap is likely to be incorrect: a plugin (unplugin-vue-i18n:directive) was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help warns in upgraded branch (sourcemaps overhead?)
  • The biggest step is for generate module graph stage (164s of total 170s in prod) and it is not from plugin hooks.

If anyone has relatively smaller projects (Nuxt or Nitro both fine) that slows down (in order of several seconds) only by upgrading Nitro to 2.10 please share it would be super helpful 🙏🏼


build 1 (extra prerender)
BUILD (14.7s)

initialize (10.535ms)
  (unknown)                                6.212ms
  plugin 3 (unimport) - buildStart         3.519ms
  plugin 21 (commonjs) - buildStart        0.363ms
  plugin 20 (node-resolve) - buildStart    0.318ms
  plugin 18 (alias) - buildStart           0.108ms
  plugin 6 (replace) - buildStart          0.015ms

generate module graph (13.657s)
  (unknown)                                6.872s
  generate ast                             1.362s
  plugin 23 (inject) - transform           1.226s
  plugin 19 (node-externals) - resolveId   590.832ms
  plugin 2 (impound) - resolveId           442.001ms
  plugin 9 (virtual) - resolveId           274.211ms
  plugin 12 (virtual) - resolveId          242.525ms
  plugin 11 (virtual) - resolveId          238.853ms
  plugin 10 (virtual) - resolveId          234.539ms
  plugin 14 (virtual) - resolveId          225.318ms
  plugin 15 (virtual) - resolveId          224.386ms
  plugin 21 (commonjs) - transform         222.77ms
  plugin 16 (virtual) - resolveId          219.394ms
  plugin 13 (virtual) - resolveId          216.887ms
  plugin 17 (virtual) - resolveId          213.313ms
  plugin 18 (alias) - resolveId            203.258ms
  plugin 6 (replace) - transform           156.261ms
  plugin 20 (node-resolve) - resolveId     150.604ms
  plugin 1 (impound) - resolveId           103.337ms
  plugin 8 (dynamic-require) - resolveId   82.622ms
  plugin 4 (raw) - resolveId               62.809ms
  plugin 0 (commonjs--resolver) - resolveId 52.991ms
  plugin 16 (virtual) - load               15.528ms
  plugin 8 (dynamic-require) - transform   6.173ms
  plugin 9 (virtual) - load                3.054ms
  plugin 3 (unimport) - transform          1.83ms
  plugin 14 (virtual) - load               1.596ms
  plugin 7 (esbuild) - transform           1.377ms
  plugin 21 (commonjs) - load              1.344ms
  plugin 10 (virtual) - load               1.004ms
  plugin 22 (json) - transform             0.982ms
  plugin 4 (raw) - load                    0.974ms
  plugin 8 (dynamic-require) - load        0.857ms
  plugin 4 (raw) - transform               0.836ms
  plugin 20 (node-resolve) - load          0.826ms
  plugin 17 (virtual) - load               0.666ms
  plugin 15 (virtual) - load               0.586ms
  plugin 13 (virtual) - load               0.578ms
  plugin 11 (virtual) - load               0.578ms
  plugin 12 (virtual) - load               0.503ms

sort and bind modules (65.284ms)

mark included statements (966.814ms)
  treeshaking pass 15                      150.628ms
  treeshaking pass 9                       74.312ms
  treeshaking pass 10                      68.193ms
  treeshaking pass 14                      47.911ms
  treeshaking pass 11                      46.11ms
  treeshaking pass 17                      42.415ms
  treeshaking pass 16                      41.211ms
  treeshaking pass 12                      38.365ms
  treeshaking pass 23                      35.965ms
  treeshaking pass 13                      35.307ms
  treeshaking pass 24                      34.915ms
  treeshaking pass 20                      34.423ms
  treeshaking pass 22                      34.085ms
  treeshaking pass 18                      33.802ms
  treeshaking pass 26                      33.777ms
  treeshaking pass 19                      33.681ms
  treeshaking pass 27                      33.563ms
  treeshaking pass 21                      32.96ms
  treeshaking pass 25                      32.743ms
  treeshaking pass 4                       19.128ms
  treeshaking pass 6                       16.244ms
  treeshaking pass 2                       11.089ms
  treeshaking pass 5                       10.088ms
  treeshaking pass 3                       9.408ms
  treeshaking pass 8                       6.767ms
  treeshaking pass 7                       5.502ms
  treeshaking pass 1                       3.768ms
  plugin 19 (node-externals) - buildEnd    0.221ms
  (unknown)                                0.203ms
  plugin 21 (commonjs) - buildEnd          0.032ms
build 2 (prerender)
ℹ Prerendering

BUILD (14.051s)

initialize (4.176ms)
  (unknown)                                2.043ms
  plugin 3 (unimport) - buildStart         1.814ms
  plugin 21 (commonjs) - buildStart        0.225ms
  plugin 20 (node-resolve) - buildStart    0.062ms
  plugin 18 (alias) - buildStart           0.018ms
  plugin 6 (replace) - buildStart          0.015ms

generate module graph (13.042s)
  (unknown)                                6.381s
  plugin 23 (inject) - transform           1.201s
  generate ast                             1.118s
  plugin 19 (node-externals) - resolveId   508.149ms
  plugin 2 (impound) - resolveId           415.814ms
  plugin 9 (virtual) - resolveId           316.706ms
  plugin 17 (virtual) - resolveId          271.009ms
  plugin 10 (virtual) - resolveId          270.71ms
  plugin 13 (virtual) - resolveId          268.529ms
  plugin 16 (virtual) - resolveId          263.826ms
  plugin 15 (virtual) - resolveId          262.893ms
  plugin 12 (virtual) - resolveId          261.458ms
  plugin 14 (virtual) - resolveId          256.908ms
  plugin 11 (virtual) - resolveId          249.994ms
  plugin 18 (alias) - resolveId            206.173ms
  plugin 21 (commonjs) - transform         205.266ms
  plugin 6 (replace) - transform           145.445ms
  plugin 20 (node-resolve) - resolveId     136.688ms
  plugin 1 (impound) - resolveId           87.584ms
  plugin 8 (dynamic-require) - resolveId   85.618ms
  plugin 4 (raw) - resolveId               57.635ms
  plugin 0 (commonjs--resolver) - resolveId 46.116ms
  plugin 16 (virtual) - load               11.752ms
  plugin 8 (dynamic-require) - transform   4.414ms
  plugin 3 (unimport) - transform          1.404ms
  plugin 7 (esbuild) - transform           0.971ms
  plugin 14 (virtual) - load               0.966ms
  plugin 21 (commonjs) - load              0.63ms
  plugin 22 (json) - transform             0.578ms
  plugin 10 (virtual) - load               0.576ms
  plugin 4 (raw) - load                    0.568ms
  plugin 4 (raw) - transform               0.548ms
  plugin 8 (dynamic-require) - load        0.465ms
  plugin 9 (virtual) - load                0.465ms
  plugin 17 (virtual) - load               0.458ms
  plugin 20 (node-resolve) - load          0.414ms
  plugin 12 (virtual) - load               0.41ms
  plugin 13 (virtual) - load               0.398ms
  plugin 15 (virtual) - load               0.36ms
  plugin 11 (virtual) - load               0.359ms

sort and bind modules (95.728ms)

mark included statements (908.775ms)
  treeshaking pass 15                      74.83ms
  treeshaking pass 10                      73.649ms
  treeshaking pass 9                       72.637ms
  treeshaking pass 14                      47.473ms
  treeshaking pass 11                      46.145ms
  treeshaking pass 16                      43.623ms
  treeshaking pass 26                      39.599ms
  treeshaking pass 19                      38.22ms
  treeshaking pass 12                      38.185ms
  treeshaking pass 13                      36.36ms
  treeshaking pass 23                      36.217ms
  treeshaking pass 20                      35.7ms
  treeshaking pass 21                      34.803ms
  treeshaking pass 17                      33.443ms
  treeshaking pass 27                      33.385ms
  treeshaking pass 18                      32.97ms
  treeshaking pass 25                      32.395ms
  treeshaking pass 22                      31.981ms
  treeshaking pass 24                      30.566ms
  treeshaking pass 4                       23.453ms
  treeshaking pass 2                       20.848ms
  treeshaking pass 5                       13.766ms
  treeshaking pass 6                       11.012ms
  treeshaking pass 3                       9.148ms
  treeshaking pass 7                       9.063ms
  treeshaking pass 8                       6.522ms
  treeshaking pass 1                       2.559ms
  (unknown)                                0.214ms
  plugin 19 (node-externals) - buildEnd    0.007ms
  plugin 21 (commonjs) - buildEnd          0.003ms
build 3 (production)
BUILD (170.366s)

initialize (5.6ms)
  (unknown)                                3.134ms
  plugin 4 (unimport) - buildStart         2.416ms
  plugin 22 (commonjs) - buildStart        0.018ms
  plugin 21 (node-resolve) - buildStart    0.017ms
  plugin 19 (alias) - buildStart           0.011ms
  plugin 7 (replace) - buildStart          0.004ms

generate module graph (164.277s)
  (unknown)                                157.506s
  generate ast                             1.308s
  plugin 24 (inject) - transform           1.088s
  plugin 20 (node-externals) - resolveId   666.087ms
  plugin 2 (impound) - resolveId           438.972ms
  plugin 7 (replace) - transform           392.37ms
  plugin 10 (virtual) - resolveId          259.895ms
  plugin 18 (virtual) - resolveId          233.579ms
  plugin 12 (virtual) - resolveId          226.639ms
  plugin 13 (virtual) - resolveId          225.376ms
  plugin 22 (commonjs) - transform         219.203ms
  plugin 16 (virtual) - resolveId          219.011ms
  plugin 17 (virtual) - resolveId          216.902ms
  plugin 15 (virtual) - resolveId          216.348ms
  plugin 11 (virtual) - resolveId          209.446ms
  plugin 14 (virtual) - resolveId          207.443ms
  plugin 19 (alias) - resolveId            185.727ms
  plugin 21 (node-resolve) - resolveId     142.222ms
  plugin 1 (impound) - resolveId           91.907ms
  plugin 9 (dynamic-require) - resolveId   82.209ms
  plugin 5 (raw) - resolveId               58.254ms
  plugin 0 (commonjs--resolver) - resolveId 46.706ms
  plugin 17 (virtual) - load               15.369ms
  plugin 9 (dynamic-require) - transform   5.701ms
  plugin 3 (nuxt:sourcemap-import) - load  3.959ms
  plugin 4 (unimport) - transform          1.718ms
  plugin 15 (virtual) - load               1.361ms
  plugin 5 (raw) - transform               1.275ms
  plugin 8 (esbuild) - transform           1.001ms
  plugin 5 (raw) - load                    0.901ms
  plugin 11 (virtual) - load               0.842ms
  plugin 22 (commonjs) - load              0.788ms
  plugin 23 (json) - transform             0.775ms
  plugin 10 (virtual) - load               0.586ms
  plugin 9 (dynamic-require) - load        0.439ms
  plugin 21 (node-resolve) - load          0.407ms
  plugin 12 (virtual) - load               0.364ms
  plugin 14 (virtual) - load               0.34ms
  plugin 16 (virtual) - load               0.334ms
  plugin 13 (virtual) - load               0.333ms
  plugin 18 (virtual) - load               0.33ms

sort and bind modules (77.559ms)

mark included statements (1.197s)
  treeshaking pass 9                       235.437ms
  treeshaking pass 10                      144.71ms
  treeshaking pass 15                      80.844ms
  treeshaking pass 14                      50.142ms
  treeshaking pass 11                      49.04ms
  treeshaking pass 16                      44.522ms
  treeshaking pass 12                      40.975ms
  treeshaking pass 13                      38.836ms
  treeshaking pass 17                      38.834ms
  treeshaking pass 18                      37.385ms
  treeshaking pass 22                      37.247ms
  treeshaking pass 21                      37.035ms
  treeshaking pass 25                      36.88ms
  treeshaking pass 19                      36.79ms
  treeshaking pass 24                      36.346ms
  treeshaking pass 27                      35.832ms
  treeshaking pass 23                      35.812ms
  treeshaking pass 20                      35.666ms
  treeshaking pass 26                      34.922ms
  treeshaking pass 8                       21.98ms
  treeshaking pass 4                       21.761ms
  treeshaking pass 6                       16.077ms
  treeshaking pass 5                       14.657ms
  treeshaking pass 3                       14.002ms
  treeshaking pass 7                       10.403ms
  treeshaking pass 2                       7.655ms
  treeshaking pass 1                       3.054ms
  plugin 20 (node-externals) - buildEnd    1.057ms
  plugin 22 (commonjs) - buildEnd          0.043ms
  (unknown)                                -0.887ms

(1) I used rollup built-in perf flag. If you want to locally do, it a little bit tricky you need to enable rollupConfig.perf and then access build result which is currently not exposed via Nitro hooks (need patching node_modules/nitropack/dist/core/index.mjs ~L1570). I made a custom reporter

@Aareksio
Copy link
Contributor Author

Aareksio commented Nov 7, 2024

Here are the results from the ~150s project I have described, this time running without docker for my convenience, it is still 2x slower than previously:


Nitro 2.10.3 - prerender phase of Nuxt
BUILD (30.418s)

initialize (1.93ms)
  plugin 3 (unimport) - buildStart         1.149ms
  (unknown)                                0.467ms
  plugin 21 (commonjs) - buildStart        0.19ms
  plugin 20 (node-resolve) - buildStart    0.071ms
  plugin 18 (alias) - buildStart           0.046ms
  plugin 6 (replace) - buildStart          0.007ms

generate module graph (29.451s)
  (unknown)                                21.075s
  plugin 19 (node-externals) - resolveId   846.776ms
  plugin 2 (impound) - resolveId           653.101ms
  plugin 9 (virtual) - resolveId           525.124ms
  generate ast                             519.381ms
  plugin 23 (inject) - transform           490.651ms
  plugin 10 (virtual) - resolveId          428.613ms
  plugin 15 (virtual) - resolveId          426.197ms
  plugin 14 (virtual) - resolveId          418.779ms
  plugin 11 (virtual) - resolveId          409.507ms
  plugin 18 (alias) - resolveId            409.047ms
  plugin 20 (node-resolve) - resolveId     406.746ms
  plugin 12 (virtual) - resolveId          402.607ms
  plugin 13 (virtual) - resolveId          399.312ms
  plugin 16 (virtual) - resolveId          398.959ms
  plugin 17 (virtual) - resolveId          395.99ms
  plugin 1 (impound) - resolveId           265.422ms
  plugin 8 (dynamic-require) - resolveId   255.055ms
  plugin 0 (commonjs--resolver) - resolveId 145.313ms
  plugin 4 (raw) - resolveId               144.982ms
  plugin 3 (unimport) - transform          112.483ms
  plugin 21 (commonjs) - transform         106.104ms
  plugin 6 (replace) - transform           70.833ms
  plugin 7 (esbuild) - transform           50.265ms
  plugin 16 (virtual) - load               16.03ms
  plugin 8 (dynamic-require) - transform   9.145ms
  plugin 4 (raw) - load                    6.667ms
  plugin 8 (dynamic-require) - load        5.76ms
  plugin 21 (commonjs) - load              5.491ms
  plugin 9 (virtual) - load                5.419ms
  plugin 4 (raw) - transform               5.259ms
  plugin 22 (json) - transform             5.124ms
  plugin 10 (virtual) - load               4.868ms
  plugin 13 (virtual) - load               4.801ms
  plugin 20 (node-resolve) - load          4.761ms
  plugin 14 (virtual) - load               4.712ms
  plugin 11 (virtual) - load               4.139ms
  plugin 17 (virtual) - load               4.112ms
  plugin 15 (virtual) - load               3.999ms
  plugin 12 (virtual) - load               3.977ms

sort and bind modules (67.586ms)

mark included statements (897.655ms)
  treeshaking pass 15                      78.47ms
  treeshaking pass 17                      57.893ms
  treeshaking pass 16                      56.716ms
  treeshaking pass 14                      46.081ms
  treeshaking pass 11                      43.971ms
  treeshaking pass 18                      43.191ms
  treeshaking pass 19                      42.203ms
  treeshaking pass 10                      41.009ms
  treeshaking pass 9                       40.126ms
  treeshaking pass 23                      38.158ms
  treeshaking pass 20                      37.71ms
  treeshaking pass 27                      37.549ms
  treeshaking pass 22                      36.849ms
  treeshaking pass 21                      36.25ms
  treeshaking pass 26                      35.409ms
  treeshaking pass 24                      35.104ms
  treeshaking pass 25                      34.878ms
  treeshaking pass 13                      34.847ms
  treeshaking pass 12                      34.102ms
  treeshaking pass 8                       32.011ms
  treeshaking pass 2                       15.497ms
  treeshaking pass 1                       8.314ms
  treeshaking pass 5                       7.84ms
  treeshaking pass 6                       7.252ms
  treeshaking pass 3                       5.785ms
  treeshaking pass 4                       5.606ms
  treeshaking pass 7                       4.105ms
  (unknown)                                0.467ms
  plugin 19 (node-externals) - buildEnd    0.225ms
  plugin 21 (commonjs) - buildEnd          0.039ms
Nitro 2.10.3 - build phase of Nuxt
BUILD (68.618s)

initialize (1.669ms)
  plugin 4 (unimport) - buildStart         1.181ms
  (unknown)                                0.376ms
  plugin 22 (commonjs) - buildStart        0.082ms
  plugin 21 (node-resolve) - buildStart    0.015ms
  plugin 19 (alias) - buildStart           0.008ms
  plugin 7 (replace) - buildStart          0.007ms

generate module graph (61.209s)
  (unknown)                                53.041s
  plugin 20 (node-externals) - resolveId   918.953ms
  generate ast                             575.389ms
  plugin 2 (impound) - resolveId           561.144ms
  plugin 24 (inject) - transform           511.948ms
  plugin 10 (virtual) - resolveId          500.074ms
  plugin 12 (virtual) - resolveId          405.605ms
  plugin 11 (virtual) - resolveId          398.7ms
  plugin 21 (node-resolve) - resolveId     395.101ms
  plugin 14 (virtual) - resolveId          394.732ms
  plugin 13 (virtual) - resolveId          386.407ms
  plugin 15 (virtual) - resolveId          384.763ms
  plugin 16 (virtual) - resolveId          381.358ms
  plugin 18 (virtual) - resolveId          378.179ms
  plugin 17 (virtual) - resolveId          374.841ms
  plugin 19 (alias) - resolveId            332.351ms
  plugin 1 (impound) - resolveId           231.6ms
  plugin 9 (dynamic-require) - resolveId   215.139ms
  plugin 0 (commonjs--resolver) - resolveId 144.869ms
  plugin 7 (replace) - transform           143.272ms
  plugin 5 (raw) - resolveId               131.352ms
  plugin 4 (unimport) - transform          119.995ms
  plugin 22 (commonjs) - transform         112.944ms
  plugin 8 (esbuild) - transform           49.349ms
  plugin 3 (nuxt:sourcemap-import) - load  47.978ms
  plugin 17 (virtual) - load               13.431ms
  plugin 9 (dynamic-require) - transform   10.104ms
  plugin 5 (raw) - transform               6.879ms
  plugin 23 (json) - transform             5.103ms
  plugin 5 (raw) - load                    4.349ms
  plugin 22 (commonjs) - load              3.78ms
  plugin 9 (dynamic-require) - load        3.103ms
  plugin 10 (virtual) - load               3.035ms
  plugin 16 (virtual) - load               2.967ms
  plugin 21 (node-resolve) - load          2.934ms
  plugin 15 (virtual) - load               2.863ms
  plugin 18 (virtual) - load               2.711ms
  plugin 11 (virtual) - load               2.583ms
  plugin 12 (virtual) - load               2.532ms
  plugin 14 (virtual) - load               2.51ms
  plugin 13 (virtual) - load               2.504ms

sort and bind modules (82.026ms)

mark included statements (1.043s)
  treeshaking pass 15                      85.777ms
  treeshaking pass 16                      61.491ms
  treeshaking pass 17                      60.172ms
  treeshaking pass 14                      50.754ms
  treeshaking pass 18                      50.705ms
  treeshaking pass 19                      49.333ms
  treeshaking pass 21                      49.032ms
  treeshaking pass 27                      46.113ms
  treeshaking pass 10                      45.988ms
  treeshaking pass 20                      44.998ms
  treeshaking pass 25                      44.96ms
  treeshaking pass 22                      44.935ms
  treeshaking pass 24                      44.6ms
  treeshaking pass 11                      44.53ms
  treeshaking pass 23                      44.11ms
  treeshaking pass 26                      43.265ms
  treeshaking pass 9                       40.654ms
  treeshaking pass 12                      40.092ms
  treeshaking pass 13                      37.01ms
  treeshaking pass 8                       33.574ms
  treeshaking pass 3                       18.966ms
  treeshaking pass 4                       15.601ms
  treeshaking pass 5                       12.715ms
  treeshaking pass 7                       11.45ms
  treeshaking pass 6                       11.022ms
  treeshaking pass 2                       6.323ms
  treeshaking pass 1                       3.896ms
  plugin 20 (node-externals) - buildEnd    1.19ms
  plugin 22 (commonjs) - buildEnd          0.006ms
  (unknown)                                -0.737ms
Nitro 2.9.7 - prerender phase of Nuxt
BUILD (11.264s)

initialize (1.663ms)
  plugin 2 (unimport) - buildStart         1.074ms
  (unknown)                                0.311ms
  plugin 19 (commonjs) - buildStart        0.155ms
  plugin 18 (node-resolve) - buildStart    0.071ms
  plugin 16 (alias) - buildStart           0.045ms
  plugin 5 (replace) - buildStart          0.007ms

generate module graph (10.354s)
  (unknown)                                7.361s
  generate ast                             507.734ms
  plugin 21 (inject) - transform           471.694ms
  plugin 17 (node-externals) - resolveId   214.144ms
  plugin 1 (impound) - resolveId           167.181ms
  plugin 18 (node-resolve) - resolveId     120.932ms
  plugin 2 (unimport) - transform          118.561ms
  plugin 8 (virtual) - resolveId           115.884ms
  plugin 10 (virtual) - resolveId          110.28ms
  plugin 19 (commonjs) - transform         107.624ms
  plugin 16 (alias) - resolveId            101.704ms
  plugin 11 (virtual) - resolveId          93.794ms
  plugin 14 (virtual) - resolveId          91.121ms
  plugin 9 (virtual) - resolveId           90.721ms
  plugin 12 (virtual) - resolveId          88.226ms
  plugin 15 (virtual) - resolveId          86.542ms
  plugin 13 (virtual) - resolveId          85.84ms
  plugin 0 (commonjs--resolver) - resolveId 79.13ms
  plugin 5 (replace) - transform           77.473ms
  plugin 3 (raw) - resolveId               64.405ms
  plugin 6 (esbuild) - transform           58.227ms
  plugin 7 (dynamic-require) - resolveId   54.722ms
  plugin 14 (virtual) - load               14.134ms
  plugin 7 (dynamic-require) - transform   9.614ms
  plugin 3 (raw) - load                    6.429ms
  plugin 7 (dynamic-require) - load        5.977ms
  plugin 3 (raw) - transform               5.351ms
  plugin 12 (virtual) - load               5.325ms
  plugin 8 (virtual) - load                4.9ms
  plugin 18 (node-resolve) - load          4.875ms
  plugin 19 (commonjs) - load              4.859ms
  plugin 20 (json) - transform             4.786ms
  plugin 9 (virtual) - load                4.627ms
  plugin 15 (virtual) - load               4.324ms
  plugin 10 (virtual) - load               4.279ms
  plugin 11 (virtual) - load               4.21ms
  plugin 13 (virtual) - load               4.066ms

sort and bind modules (60.764ms)

mark included statements (846.471ms)
  treeshaking pass 15                      74.098ms
  treeshaking pass 16                      65.922ms
  treeshaking pass 17                      58.385ms
  treeshaking pass 14                      48.512ms
  treeshaking pass 18                      46.639ms
  treeshaking pass 19                      41.827ms
  treeshaking pass 20                      40.254ms
  treeshaking pass 23                      37.109ms
  treeshaking pass 11                      36.863ms
  treeshaking pass 21                      36.124ms
  treeshaking pass 10                      36.085ms
  treeshaking pass 24                      35.729ms
  treeshaking pass 22                      35.669ms
  treeshaking pass 27                      35.032ms
  treeshaking pass 26                      34.713ms
  treeshaking pass 25                      34.683ms
  treeshaking pass 9                       33.206ms
  treeshaking pass 12                      31.391ms
  treeshaking pass 13                      29.01ms
  treeshaking pass 8                       27.994ms
  treeshaking pass 3                       6.823ms
  treeshaking pass 5                       5.646ms
  treeshaking pass 4                       4.784ms
  treeshaking pass 6                       4.758ms
  treeshaking pass 7                       3.67ms
  treeshaking pass 1                       0.645ms
  treeshaking pass 2                       0.442ms
  plugin 17 (node-externals) - buildEnd    0.349ms
  (unknown)                                0.072ms
  plugin 19 (commonjs) - buildEnd          0.039ms
Nitro 2.9.7 - build phase of Nuxt
BUILD (23.121s)

initialize (1.515ms)
  plugin 3 (unimport) - buildStart         1.108ms
  (unknown)                                0.361ms
  plugin 20 (commonjs) - buildStart        0.018ms
  plugin 19 (node-resolve) - buildStart    0.013ms
  plugin 17 (alias) - buildStart           0.007ms
  plugin 6 (replace) - buildStart          0.006ms

generate module graph (15.888s)
  (unknown)                                12.698s
  generate ast                             593.646ms
  plugin 22 (inject) - transform           540.958ms
  plugin 18 (node-externals) - resolveId   204.004ms
  plugin 1 (impound) - resolveId           162.51ms
  plugin 6 (replace) - transform           141.938ms
  plugin 9 (virtual) - resolveId           137.567ms
  plugin 19 (node-resolve) - resolveId     117.529ms
  plugin 3 (unimport) - transform          116.72ms
  plugin 20 (commonjs) - transform         116.587ms
  plugin 11 (virtual) - resolveId          94.886ms
  plugin 14 (virtual) - resolveId          94.776ms
  plugin 10 (virtual) - resolveId          94.041ms
  plugin 12 (virtual) - resolveId          90.69ms
  plugin 15 (virtual) - resolveId          89.04ms
  plugin 17 (alias) - resolveId            88.769ms
  plugin 13 (virtual) - resolveId          85.476ms
  plugin 16 (virtual) - resolveId          85.096ms
  plugin 0 (commonjs--resolver) - resolveId 67.555ms
  plugin 4 (raw) - resolveId               61.334ms
  plugin 8 (dynamic-require) - resolveId   48.196ms
  plugin 7 (esbuild) - transform           48.034ms
  plugin 2 (nuxt:sourcemap-import) - load  44.448ms
  plugin 15 (virtual) - load               13.276ms
  plugin 8 (dynamic-require) - transform   10.026ms
  plugin 4 (raw) - transform               5.872ms
  plugin 21 (json) - transform             5.15ms
  plugin 4 (raw) - load                    3.773ms
  plugin 20 (commonjs) - load              3.171ms
  plugin 9 (virtual) - load                3.057ms
  plugin 8 (dynamic-require) - load        3.02ms
  plugin 19 (node-resolve) - load          2.902ms
  plugin 13 (virtual) - load               2.704ms
  plugin 10 (virtual) - load               2.617ms
  plugin 16 (virtual) - load               2.582ms
  plugin 12 (virtual) - load               2.493ms
  plugin 14 (virtual) - load               2.46ms
  plugin 11 (virtual) - load               2.437ms

sort and bind modules (69.251ms)

mark included statements (907.038ms)
  treeshaking pass 15                      89.166ms
  treeshaking pass 16                      57.58ms
  treeshaking pass 17                      53.114ms
  treeshaking pass 14                      48.77ms
  treeshaking pass 18                      44.566ms
  treeshaking pass 19                      42.552ms
  treeshaking pass 23                      39.72ms
  treeshaking pass 20                      39.297ms
  treeshaking pass 21                      39.158ms
  treeshaking pass 24                      39.074ms
  treeshaking pass 27                      38.759ms
  treeshaking pass 22                      38.525ms
  treeshaking pass 25                      38.478ms
  treeshaking pass 26                      38.226ms
  treeshaking pass 10                      37.684ms
  treeshaking pass 11                      37.387ms
  treeshaking pass 9                       35.011ms
  treeshaking pass 12                      34.115ms
  treeshaking pass 13                      32.868ms
  treeshaking pass 8                       31.509ms
  treeshaking pass 5                       12.135ms
  treeshaking pass 4                       11.554ms
  treeshaking pass 7                       9.797ms
  treeshaking pass 6                       8.975ms
  treeshaking pass 3                       6.496ms
  treeshaking pass 2                       1.547ms
  plugin 18 (node-externals) - buildEnd    0.948ms
  treeshaking pass 1                       0.608ms
  plugin 20 (commonjs) - buildEnd          0.005ms
  (unknown)                                -0.588ms

Now, I could not replicate the fast results when downgrading. To my understanding, this means the reason lies within one of the dependencies, a dependency which is present in both 2.9.3 and 2.10.3, and is semver compatible between both versions.

$ git reset --hard $HEAD
$ rm -rf node_modules pnpm-lock.yaml && pnpm add -D [email protected]
$ pnpm build # fast
$ rm -rf node_modules pnpm-lock.yaml && pnpm add -D [email protected]
$ pnpm build # slow
$ rm pnpm-lock.yaml && pnpm add -D [email protected]
$ pnpm build # slow, is it re-using some deps from node_modules?
$ rm -rf node_modules pnpm-lock.yaml && pnpm add -D [email protected]
$ pnpm build # fast again

@Aareksio
Copy link
Contributor Author

Aareksio commented Nov 7, 2024

Playing with it a bit more: I have a project with [email protected] and additional dev dependency [email protected]. It builds slowly. When downgrading with pnpm add -D [email protected] it still builds slowly. However, when updating the version in package.json and running pnpm install it builds fast. Maybe that helps 🤔

@Aareksio
Copy link
Contributor Author

Aareksio commented Nov 7, 2024

Playing with a bit more, most of what I stated above is bullshit. Dependencies are hard. I was on this yesterday, yet somehow totally forgot by the morning. Turns out running actual debugger instead of guessing is very useful, too.

{ "pnpm": { "overrides": { "nitropack": "$VERSION" } }

3.9.7: 10s
2.10.0: 10s
2.10.1: 41s
2.10.2: 24s
2.10.3: 24s

Reproducible, to lesser degree but reproducible, on StackBlitz with hello-world. Probably degraded because of #2838 and then improved (for nuxt) by #2842, probably because nuxt passes ignored paths or something like that.

Precisely, the regression is caused by moving the check on !extensions.has(extname(resolvedId)) after await this.resolve(id, importer, resolveOpts). Adding back (here) the early return fixes the regression:

    async resolveId(id, importer, resolveOpts) {
      if (id === HELPER_ID) {
        return id;
      }

      if (id[0] === "\0") {
        return;
      }

      const withRawSpecifier = id.startsWith("raw:");
      if (withRawSpecifier) {
        id = id.slice(4);
      }

+     if (!withRawSpecifier && !extensions.has(extname(id))) {
+      return;
+     }

      const resolvedId = (await this.resolve(id, importer, resolveOpts))?.id;

      if (!resolvedId || resolvedId.startsWith("\0")) {
        return resolvedId;
      }

      if (!withRawSpecifier && !extensions.has(extname(resolvedId))) {
        return;
      }

      return { id: "\0raw:" + resolvedId };
    },

@Aareksio Aareksio changed the title Build time regression in 2.10 Build time regression in 2.10.1 Nov 7, 2024
@pi0
Copy link
Member

pi0 commented Nov 7, 2024

Nice find dear @Aareksio. Any chance you could share your testing project btw? This amount of overhead for id resolution seems unusual. (your fix is good feel free to open a draft PR 🙏🏼 )

@Aareksio
Copy link
Contributor Author

Aareksio commented Nov 7, 2024

I am aware this is essentially reverting the PR and reinstalling the issue. However, resolving every single .js file with filesystem, precisely lstat, is going to cause overhead. For the project in question (which is small even for our small scale) there are over 22,000 additional resolutions. It is very abstract, but cost of time and resources wasted on build stack really strongly against convinience of .sql.ts.

Not sure how to solve the issue properly without introducing the overhead :(

@antoinezanardi
Copy link

Thanks for the investigation team. I will share the new build time when Nuxt will be updated with the new Nitro release. Stay tuned 😉

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.

4 participants