Skip to content

Commit ce10569

Browse files
Spencerelasticmachine
andauthored
[kbn/optimizer] disable parallelization in terser plugin (#58396) (#58421)
* [kbn/optimizer] disable parallelization in terer plugin * use more workers when building the dist Co-authored-by: Elastic Machine <[email protected]>
1 parent c790dd4 commit ce10569

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/kbn-optimizer/src/optimizer/optimizer_config.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ import { Bundle, WorkerConfig } from '../common';
2525
import { findKibanaPlatformPlugins, KibanaPlatformPlugin } from './kibana_platform_plugins';
2626
import { getBundles } from './get_bundles';
2727

28+
function pickMaxWorkerCount(dist: boolean) {
29+
// don't break if cpus() returns nothing, or an empty array
30+
const cpuCount = Math.max(Os.cpus()?.length, 1);
31+
// if we're buiding the dist then we can use more of the system's resources to get things done a little quicker
32+
const maxWorkers = dist ? cpuCount - 1 : Math.ceil(cpuCount / 3);
33+
// ensure we always have at least two workers
34+
return Math.max(maxWorkers, 2);
35+
}
36+
2837
interface Options {
2938
/** absolute path to root of the repo/build */
3039
repoRoot: string;
@@ -110,7 +119,7 @@ export class OptimizerConfig {
110119

111120
const maxWorkerCount = process.env.KBN_OPTIMIZER_MAX_WORKERS
112121
? parseInt(process.env.KBN_OPTIMIZER_MAX_WORKERS, 10)
113-
: options.maxWorkerCount ?? Math.max(Math.ceil(Math.max(Os.cpus()?.length, 1) / 3), 2);
122+
: options.maxWorkerCount ?? pickMaxWorkerCount(dist);
114123
if (typeof maxWorkerCount !== 'number' || !Number.isFinite(maxWorkerCount)) {
115124
throw new TypeError('worker count must be a number');
116125
}

packages/kbn-optimizer/src/worker/webpack.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ export function getWebpackConfig(bundle: Bundle, worker: WorkerConfig) {
248248
cache: false,
249249
sourceMap: false,
250250
extractComments: false,
251+
parallel: false,
251252
terserOptions: {
252253
compress: false,
253254
mangle: false,

0 commit comments

Comments
 (0)