Skip to content

Commit

Permalink
fix: use cpuCount for all parallel parts (#30548)
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Apr 22, 2021
1 parent 7dd645d commit 9dbb772
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
8 changes: 3 additions & 5 deletions packages/gatsby-plugin-manifest/src/gatsby-node.js
@@ -1,18 +1,16 @@
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"

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)
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-sharp/src/gatsby-worker.js
Expand Up @@ -32,7 +32,7 @@ const q = queue(
args.pluginOptions
)
),
cpuCoreCount()
Math.max(1, cpuCoreCount() - 1)
)

/**
Expand Down
10 changes: 7 additions & 3 deletions 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"
Expand All @@ -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 {
Expand Down Expand Up @@ -661,6 +660,7 @@ export const createWebpackUtils = (
},
...terserOptions,
},
parallel: Math.max(1, cpuCoreCount() - 1),
...options,
})

Expand Down Expand Up @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/worker/pool.ts
Expand Up @@ -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,
},
Expand Down

0 comments on commit 9dbb772

Please sign in to comment.