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

perf(gatsby-plugin-sharp): change approach to concurrency for image processing #28575

Merged
merged 2 commits into from
Jan 5, 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
3 changes: 2 additions & 1 deletion packages/gatsby-plugin-sharp/src/gatsby-worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require(`path`)
const queue = require(`async/queue`)
const { cpuCoreCount } = require(`gatsby-core-utils`)
const { processFile } = require(`./process-file`)

exports.IMAGE_PROCESSING_JOB_NAME = `IMAGE_PROCESSING`
Expand Down Expand Up @@ -31,7 +32,7 @@ const q = queue(
args.pluginOptions
)
),
1
cpuCoreCount()
)

/**
Expand Down
8 changes: 3 additions & 5 deletions packages/gatsby-plugin-sharp/src/process-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ const imageminMozjpeg = require(`imagemin-mozjpeg`)
const imageminPngquant = require(`imagemin-pngquant`)
const { healOptions } = require(`./plugin-options`)
const { SharpError } = require(`./sharp-error`)
const { cpuCoreCount, createContentDigest } = require(`gatsby-core-utils`)
const { createContentDigest } = require(`gatsby-core-utils`)

// Try to enable the use of SIMD instructions. Seems to provide a smallish
// speedup on resizing heavy loads (~10%). Sharp disables this feature by
// default as there's been problems with segfaulting in the past but we'll be
// adventurous and see what happens with it on.
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())
// Concurrency is handled in gatsby-worker queue instead
sharp.concurrency(1)

/**
* @typedef DuotoneArgs
Expand Down