Unverified Commit eb65ed37 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

avoid retaining webpack config too long (#32053)

avoids keeping the webpack compiler during after webpack build build steps like SSG etc.

(review with ignore whitespace)

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
parent 5763a33a
...@@ -571,6 +571,11 @@ export default async function build( ...@@ -571,6 +571,11 @@ export default async function build(
ignore: [] as string[], ignore: [] as string[],
})) }))
let result: CompilerResult = { warnings: [], errors: [] }
let webpackBuildStart
let telemetryPlugin
await (async () => {
// IIFE to isolate locals and avoid retaining memory too long
const runWebpackSpan = nextBuildSpan.traceChild('run-webpack-compiler') const runWebpackSpan = nextBuildSpan.traceChild('run-webpack-compiler')
const configs = await runWebpackSpan const configs = await runWebpackSpan
.traceChild('generate-webpack-config') .traceChild('generate-webpack-config')
...@@ -628,9 +633,8 @@ export default async function build( ...@@ -628,9 +633,8 @@ export default async function build(
) )
} }
const webpackBuildStart = process.hrtime() webpackBuildStart = process.hrtime()
let result: CompilerResult = { warnings: [], errors: [] }
// We run client and server compilation separately to optimize for memory usage // We run client and server compilation separately to optimize for memory usage
await runWebpackSpan.traceAsyncFn(async () => { await runWebpackSpan.traceAsyncFn(async () => {
const clientResult = await runCompiler(clientConfig, { runWebpackSpan }) const clientResult = await runCompiler(clientConfig, { runWebpackSpan })
...@@ -660,16 +664,19 @@ export default async function build( ...@@ -660,16 +664,19 @@ export default async function build(
} }
} }
}) })
result = nextBuildSpan
.traceChild('format-webpack-messages')
.traceFn(() => formatWebpackMessages(result, true))
telemetryPlugin = (clientConfig as webpack.Configuration).plugins?.find(
isTelemetryPlugin
)
})()
const webpackBuildEnd = process.hrtime(webpackBuildStart) const webpackBuildEnd = process.hrtime(webpackBuildStart)
if (buildSpinner) { if (buildSpinner) {
buildSpinner.stopAndPersist() buildSpinner.stopAndPersist()
} }
result = nextBuildSpan
.traceChild('format-webpack-messages')
.traceFn(() => formatWebpackMessages(result, true))
if (result.errors.length > 0) { if (result.errors.length > 0) {
// Only keep the first few errors. Others are often indicative // Only keep the first few errors. Others are often indicative
// of the same problem, but confuse the reader with noise. // of the same problem, but confuse the reader with noise.
...@@ -1871,9 +1878,6 @@ export default async function build( ...@@ -1871,9 +1878,6 @@ export default async function build(
}) })
) )
const telemetryPlugin = (
clientConfig as webpack.Configuration
).plugins?.find(isTelemetryPlugin)
if (telemetryPlugin) { if (telemetryPlugin) {
const events = eventBuildFeatureUsage(telemetryPlugin) const events = eventBuildFeatureUsage(telemetryPlugin)
telemetry.record(events) telemetry.record(events)
......
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