Small speedups for `nitro dev` and `nitro build`
Los mantenedores suelen responder en 2 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 42/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- node.js, typescript, vite
- Área
- backend, build-system, performance
Línea de trabajo
The issue groups four CLI speedups and links comparison branches for each; start by reading the linked changes and the related #4939. Check which changes the maintainers want before choosing one, then compare its measurements and scope with the described baseline. Done means the selected optimization is implemented and its reported CLI timing or module loading improvement is confirmed.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I measured where the Nitro CLI spends its time on a generated app with 300 routes. Each change below is small, so I put them all in one issue instead of opening a PR for each. Tell me which ones you want, and I'll open PRs only for those.
The biggest win, reload after an edit, is in env-runner. It's in unjs/env-runner#104.
1. Turn on Node's compile cache
Each time you run nitro, Node compiles Nitro and its dependencies from scratch. For nitro build that's about 2 MB of JS. module.enableCompileCache() tells Node to save the compiled code to disk and use it again on the next run. Vite's CLI already does this.
main |
with cache | |
|---|---|---|
nitro dev, first response |
533 ms | 494 ms |
nitro build |
495 ms | 453 ms |
nitro preview, first response |
143 ms | 134 ms |
Node writes the cache when the process exits. A dev server doesn't exit, so the branch also writes it 10 seconds after start.
https://github.com/nitrojs/nitro/compare/main...onmax:nitro:perf/cli-compile-cache
2. Skip Nitro's own imports in the externals check
In dev, the nitro:externals plugin looks at each package import and decides if it stays an import or goes into the bundle. App code imports nitro and nitro/h3 in almost every file, and those always go into the bundle. In the 300-route app the plugin ran 830 times, and only 23 of those runs kept an import.
Adding /^nitro(?:\/|$)/ to noExternal lets Rolldown skip these imports without calling the plugin. The plugin now runs 23 times, and the dev bundle step goes from 155 ms to 138 ms. The Vite builder already has this pattern.
https://github.com/nitrojs/nitro/compare/main...onmax:nitro:perf/dev-externals-self-imports
3. Let Rolldown skip unwasm's renderChunk
unwasm's renderChunk only changes chunks that import a .wasm file. Rolldown still calls it for every chunk, and it copies the code of each chunk to JS for the call. The 300-route app has 519 chunks, so that's 519 calls that change nothing.
With filter: { code: "unwasm:external:" }, Rolldown skips those chunks. The Rolldown step goes from 262 ms to 252 ms. The same filter on nitro:externals takes it to 242 ms.
https://github.com/unjs/unwasm/compare/main...onmax:unwasm:perf/render-chunk-filter
https://github.com/nitrojs/nitro/compare/main...onmax:nitro:perf/build-render-chunk-filter
4. Don't load the dev server in nitro build
nitro build imports nitro/builder, and that also loads the dev server and env-runner. If the build command imports the build modules directly, it loads 26 fewer modules. That saves about 12 ms on the 300-route app. It's small, so skip it if you don't like the change. Related to #4939.
https://github.com/nitrojs/nitro/compare/main...onmax:nitro:perf/build-lazy-dev-modules
Two more ideas I measured but didn't build
import("rolldown")waits until the config has loaded, and it takes 15 to 35 ms. It only needsrootDir, so the CLI could start it earlier.copyPublicAssetscallsfsp.cpfor each file. For 150 files that takes 15 to 35 ms.mkdirpluscopyFiletakes 4 to 8 ms. ButcopyFilefollows symlinks, andcpcopies them as symlinks. So this change would need a check for symlinks.
- Lenguaje dominante
- TypeScript
- Estrellas
- 11.5k
- Forks
- 968
- Merge medio
- 4 d 9 h
- PR fusionados (30 d)
- 64
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de nitrojs/nitro
-
pending triage
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
Los mantenedores suelen responder en 2 días
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 95/100
Los mantenedores suelen responder en 2 días
-
cloudflare: `nitro deploy` fails when a parent directory has a Wrangler configPosiblemente ocupada @draarivpatel-ui la tomó hace 13 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
Los mantenedores suelen responder en 2 días
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 2 días
-
pending triage
Dificultad 5/5 Más de una semana Aptitud para principiantes 30/100
nitrojs/nitro#5205 · 1 reacción ·
Los mantenedores suelen responder en 2 días
Todos los issues de nitrojs/nitro
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 95/100
amosblomqvist/learnharness#1141 ·
Los mantenedores suelen responder en 4 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
ranxianglei/billion-context#8319 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
tencent-connect/dsh-qqbot#148 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
JimLiu/open-artifact#126 ·
-
redis.expireTime() returns relative TTL seconds on live host instead of Unix timestamp secondsAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100