perf: reduce build tree view allocations (#99930)
## Summary `printTreeView` copied generated-route lists several times and created a temporary object for every route before printing a small preview in the build output. This change writes the preview directly to the output table. When routes need to be reordered, it sorts one list of numeric indexes instead of copying the routes into objects. The build output does not change. The function creates less temporary data and puts less pressure on garbage collection during builds with many generated routes. ## Impact In a focused A/B of the compiled `printTreeView` with 50,000 generated routes, median temporary heap growth per call dropped: - from 460 KB to 68 KB when preserving route order (-85%) - from 4.53 MB to 2.14 MB when ordering slow routes first (-53%) These results were repeated across five fresh Node.js processes with 50 samples per process. This is a memory-allocation improvement; no CPU-time improvement is claimed. ## Verification - `pnpm build-all` - `HEADLESS=true pnpm test-start-turbo test/e2e/app-dir/build-output-truncated-generated-paths/build-output-truncated-generated-paths.test.ts` - `HEADLESS=true pnpm test-start-webpack test/e2e/app-dir/build-output-truncated-generated-paths/build-output-truncated-generated-paths.test.ts` <!-- NEXT_JS_LLM -->
Showing
Please
register
or
sign in
to comment