From 9dbb77238f23eedbb9b6dcf5ffb3453cb67bc9b8 Mon Sep 17 00:00:00 2001 From: Ward Peeters Date: Thu, 22 Apr 2021 18:28:41 +0200 Subject: [PATCH] fix: use cpuCount for all parallel parts (#30548) --- packages/gatsby-plugin-manifest/src/gatsby-node.js | 8 +++----- packages/gatsby-plugin-sharp/src/gatsby-worker.js | 2 +- packages/gatsby/src/utils/webpack-utils.ts | 10 +++++++--- packages/gatsby/src/utils/worker/pool.ts | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/gatsby-plugin-manifest/src/gatsby-node.js b/packages/gatsby-plugin-manifest/src/gatsby-node.js index 927671797ceac..b19d50b798da7 100644 --- a/packages/gatsby-plugin-manifest/src/gatsby-node.js +++ b/packages/gatsby-plugin-manifest/src/gatsby-node.js @@ -1,7 +1,7 @@ import * as fs from "fs" import * as path from "path" import sharp from "./safe-sharp" -import { createContentDigest, cpuCoreCount, slash } from "gatsby-core-utils" +import { createContentDigest, slash } from "gatsby-core-utils" import { defaultIcons, addDigestToPath, favicons } from "./common" import { doesIconExist } from "./node-helpers" @@ -9,10 +9,8 @@ import pluginOptionsSchema from "./pluginOptionsSchema" sharp.simd(true) -// Handle Sharp's concurrency based on the Gatsby CPU count -// See: http://sharp.pixelplumbing.com/en/stable/api-utility/#concurrency -// See: https://www.gatsbyjs.org/docs/multi-core-builds/ -sharp.concurrency(cpuCoreCount()) +// force it to be 1 as we only resize one image +sharp.concurrency(1) async function generateIcon(icon, srcIcon) { const imgPath = path.join(`public`, icon.src) diff --git a/packages/gatsby-plugin-sharp/src/gatsby-worker.js b/packages/gatsby-plugin-sharp/src/gatsby-worker.js index e8c1b212e45cf..bfbb3f00e46e1 100644 --- a/packages/gatsby-plugin-sharp/src/gatsby-worker.js +++ b/packages/gatsby-plugin-sharp/src/gatsby-worker.js @@ -32,7 +32,7 @@ const q = queue( args.pluginOptions ) ), - cpuCoreCount() + Math.max(1, cpuCoreCount() - 1) ) /** diff --git a/packages/gatsby/src/utils/webpack-utils.ts b/packages/gatsby/src/utils/webpack-utils.ts index c3fa306bd40c2..921b7c93dcd0c 100644 --- a/packages/gatsby/src/utils/webpack-utils.ts +++ b/packages/gatsby/src/utils/webpack-utils.ts @@ -1,7 +1,6 @@ import * as path from "path" import { Loader, RuleSetRule, Plugin } from "webpack" import { GraphQLSchema } from "graphql" -import postcss from "postcss" import autoprefixer from "autoprefixer" import flexbugs from "postcss-flexbugs-fixes" import TerserPlugin from "terser-webpack-plugin" @@ -10,7 +9,7 @@ import CssMinimizerPlugin from "css-minimizer-webpack-plugin" import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin" import { getBrowsersList } from "./browserslist" import ESLintPlugin from "eslint-webpack-plugin" - +import { cpuCoreCount } from "gatsby-core-utils" import { GatsbyWebpackStatsExtractor } from "./gatsby-webpack-stats-extractor" import { GatsbyWebpackEslintGraphqlSchemaReload } from "./gatsby-webpack-eslint-graphql-schema-reload-plugin" import { @@ -661,6 +660,7 @@ export const createWebpackUtils = ( }, ...terserOptions, }, + parallel: Math.max(1, cpuCoreCount() - 1), ...options, }) @@ -729,7 +729,11 @@ export const createWebpackUtils = ( ], }, } - ): CssMinimizerPlugin => new CssMinimizerPlugin(options) + ): CssMinimizerPlugin => + new CssMinimizerPlugin({ + parallel: Math.max(1, cpuCoreCount() - 1), + ...options, + }) plugins.fastRefresh = ({ modulesThatUseGatsby }): Plugin => { const regExpToHack = /node_modules/ diff --git a/packages/gatsby/src/utils/worker/pool.ts b/packages/gatsby/src/utils/worker/pool.ts index c322e5a0bf3bf..f5e034ecf1d68 100644 --- a/packages/gatsby/src/utils/worker/pool.ts +++ b/packages/gatsby/src/utils/worker/pool.ts @@ -3,7 +3,7 @@ import { cpuCoreCount } from "gatsby-core-utils" export const create = (): Worker => new Worker(require.resolve(`./child`), { - numWorkers: cpuCoreCount(), + numWorkers: Math.max(1, cpuCoreCount() - 1), forkOptions: { silent: false, },