Unverified Commit bde427a7 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Optimize build trace ignores (#60859)

It seems that when tracing build dependencies our server tracing was
analyzing all server chunks un-necessarily and when a very large
dependency like `ace-builds` is creating large chunks it can slow down
builds drastically so this ensures we eagerly apply our shared ignores
to avoid this over tracing.

Build times before [with provided
repro](https://github.com/MartinXPN/next-slow-build-reproduction):

```sh
▲ Next.js 14.1.0

   Creating an optimized production build ...
 ✓ Compiled successfully
 ✓ Linting and checking validity of types
 ✓ Collecting page data
 ✓ Generating static pages (5/5)
 ✓ Collecting build traces
 ✓ Finalizing page optimization

✨  Done in 437.29s.
```

Build times after [with provided
repro](https://github.com/MartinXPN/next-slow-build-reproduction):

```sh
▲ Next.js 14.1.1-canary.0

   Creating an optimized production build ...
 ✓ Compiled successfully
 ✓ Linting and checking validity of types
 ✓ Collecting page data
 ✓ Generating static pages (5/5)
 ✓ Collecting build traces
 ✓ Finalizing page optimization

✨  Done in 42.38s.
```


Closes: https://github.com/vercel/next.js/issues/58759
Closes NEXT-2161
parent 3a8436b1
...@@ -293,7 +293,7 @@ export async function collectBuildTraces({ ...@@ -293,7 +293,7 @@ export async function collectBuildTraces({
const sharedIgnores = [ const sharedIgnores = [
'**/next/dist/compiled/next-server/**/*.dev.js', '**/next/dist/compiled/next-server/**/*.dev.js',
isStandalone ? null : '**/next/dist/compiled/jest-worker/**/*', ...(isStandalone ? [] : ['**/next/dist/compiled/jest-worker/**/*']),
'**/next/dist/compiled/webpack/(bundle4|bundle5).js', '**/next/dist/compiled/webpack/(bundle4|bundle5).js',
'**/node_modules/webpack5/**/*', '**/node_modules/webpack5/**/*',
'**/next/dist/server/lib/route-resolver*', '**/next/dist/server/lib/route-resolver*',
...@@ -318,6 +318,8 @@ export async function collectBuildTraces({ ...@@ -318,6 +318,8 @@ export async function collectBuildTraces({
...(config.experimental.outputFileTracingIgnores || []), ...(config.experimental.outputFileTracingIgnores || []),
] ]
const sharedIgnoresFn = makeIgnoreFn(sharedIgnores)
const serverIgnores = [ const serverIgnores = [
...sharedIgnores, ...sharedIgnores,
'**/node_modules/react{,-dom,-dom-server-turbopack}/**/*.development.js', '**/node_modules/react{,-dom,-dom-server-turbopack}/**/*.development.js',
...@@ -417,7 +419,6 @@ export async function collectBuildTraces({ ...@@ -417,7 +419,6 @@ export async function collectBuildTraces({
...serverEntries, ...serverEntries,
...minimalServerEntries, ...minimalServerEntries,
] ]
const result = await nodeFileTrace(chunksToTrace, { const result = await nodeFileTrace(chunksToTrace, {
base: outputFileTracingRoot, base: outputFileTracingRoot,
processCwd: dir, processCwd: dir,
...@@ -460,6 +461,26 @@ export async function collectBuildTraces({ ...@@ -460,6 +461,26 @@ export async function collectBuildTraces({
throw e throw e
} }
}, },
// handle shared ignores at top-level as it
// avoids over-tracing when we don't need to
// and speeds up total trace time
ignore(p) {
if (sharedIgnoresFn(p)) {
return true
}
// if a chunk is attempting to be traced that isn't
// in our initial list we need to ignore it to prevent
// over tracing as webpack needs to be the source of
// truth for which chunks should be included for each entry
if (
p.includes('.next/server/chunks') &&
!chunksToTrace.includes(path.join(outputFileTracingRoot, p))
) {
return true
}
return false
},
}) })
const reasons = result.reasons const reasons = result.reasons
const fileList = result.fileList const fileList = result.fileList
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment