Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use cpuCount for all parallel parts #30548

Merged
merged 2 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions packages/gatsby-plugin-manifest/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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