Skip to content

Commit 9dbb772

Browse files
authored
fix: use cpuCount for all parallel parts (#30548)
1 parent 7dd645d commit 9dbb772

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

packages/gatsby-plugin-manifest/src/gatsby-node.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import * as fs from "fs"
22
import * as path from "path"
33
import sharp from "./safe-sharp"
4-
import { createContentDigest, cpuCoreCount, slash } from "gatsby-core-utils"
4+
import { createContentDigest, slash } from "gatsby-core-utils"
55
import { defaultIcons, addDigestToPath, favicons } from "./common"
66
import { doesIconExist } from "./node-helpers"
77

88
import pluginOptionsSchema from "./pluginOptionsSchema"
99

1010
sharp.simd(true)
1111

12-
// Handle Sharp's concurrency based on the Gatsby CPU count
13-
// See: http://sharp.pixelplumbing.com/en/stable/api-utility/#concurrency
14-
// See: https://www.gatsbyjs.org/docs/multi-core-builds/
15-
sharp.concurrency(cpuCoreCount())
12+
// force it to be 1 as we only resize one image
13+
sharp.concurrency(1)
1614

1715
async function generateIcon(icon, srcIcon) {
1816
const imgPath = path.join(`public`, icon.src)

packages/gatsby-plugin-sharp/src/gatsby-worker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const q = queue(
3232
args.pluginOptions
3333
)
3434
),
35-
cpuCoreCount()
35+
Math.max(1, cpuCoreCount() - 1)
3636
)
3737

3838
/**

packages/gatsby/src/utils/webpack-utils.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as path from "path"
22
import { Loader, RuleSetRule, Plugin } from "webpack"
33
import { GraphQLSchema } from "graphql"
4-
import postcss from "postcss"
54
import autoprefixer from "autoprefixer"
65
import flexbugs from "postcss-flexbugs-fixes"
76
import TerserPlugin from "terser-webpack-plugin"
@@ -10,7 +9,7 @@ import CssMinimizerPlugin from "css-minimizer-webpack-plugin"
109
import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin"
1110
import { getBrowsersList } from "./browserslist"
1211
import ESLintPlugin from "eslint-webpack-plugin"
13-
12+
import { cpuCoreCount } from "gatsby-core-utils"
1413
import { GatsbyWebpackStatsExtractor } from "./gatsby-webpack-stats-extractor"
1514
import { GatsbyWebpackEslintGraphqlSchemaReload } from "./gatsby-webpack-eslint-graphql-schema-reload-plugin"
1615
import {
@@ -661,6 +660,7 @@ export const createWebpackUtils = (
661660
},
662661
...terserOptions,
663662
},
663+
parallel: Math.max(1, cpuCoreCount() - 1),
664664
...options,
665665
})
666666

@@ -729,7 +729,11 @@ export const createWebpackUtils = (
729729
],
730730
},
731731
}
732-
): CssMinimizerPlugin => new CssMinimizerPlugin(options)
732+
): CssMinimizerPlugin =>
733+
new CssMinimizerPlugin({
734+
parallel: Math.max(1, cpuCoreCount() - 1),
735+
...options,
736+
})
733737

734738
plugins.fastRefresh = ({ modulesThatUseGatsby }): Plugin => {
735739
const regExpToHack = /node_modules/

packages/gatsby/src/utils/worker/pool.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { cpuCoreCount } from "gatsby-core-utils"
33

44
export const create = (): Worker =>
55
new Worker(require.resolve(`./child`), {
6-
numWorkers: cpuCoreCount(),
6+
numWorkers: Math.max(1, cpuCoreCount() - 1),
77
forkOptions: {
88
silent: false,
99
},

0 commit comments

Comments
 (0)