Skip to content

Commit

Permalink
perf(gatsby-plugin-sharp): change approach to concurrency for image p…
Browse files Browse the repository at this point in the history
…rocessing (#28575) (#28862)

Co-authored-by: gatsbybot <[email protected]>
(cherry picked from commit 930e6b6)

Co-authored-by: Vladimir Razuvaev <[email protected]>
  • Loading branch information
GatsbyJS Bot and vladar authored Jan 5, 2021
1 parent f04304e commit afac774
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
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

0 comments on commit afac774

Please sign in to comment.