sharp.concurrency() alone did not speed up my pipeline. With one image in flight at a time, setting it to 1, 2, 4 or 8 gave 3.8 to 4.2 images per second. Running 4 images in flight at once gave 11.0 per second at concurrency 1 and 16.3 at concurrency 4. Past 4 in flight, nothing improved, and memory rose.
So the lever is how many jobs you start, with threads per job as a smaller second setting. Here is the grid, the script, and the cost in memory.
What does sharp.concurrency() set?
The sharp utility docs say it sets the number of threads libvips uses for each pipeline. The docs give the default as the number of CPU cores, except on glibc-based Linux without jemalloc, where the default is 1. On this 8-core Mac, sharp.concurrency() returned 6 before I touched it.
It is a per-job thread count. It is not a cap on how many jobs run at once. That second number is yours to set, usually in a queue or a loop.
How do you measure throughput for both settings?
I crossed two settings: sharp.concurrency(c) for c in 1, 2, 4, 8, and the number of jobs in flight at once (1, 4, 8, 16). Each run processed 40 jobs. Each job resized our 4964 × 2782 camera photo (kept in a Buffer) to 1600 pixels wide and encoded WebP at quality 80. Each cell is a fresh process, one warm-up job excluded, median of 5 runs.
// conc.mjs (node conc.mjs <concurrency> <inflight> <jobs>)
import sharp from 'sharp';
import { readFile } from 'node:fs/promises';
const [c, inflight, jobs] = process.argv.slice(2).map(Number);
sharp.concurrency(c);
sharp.cache(false);
const src = await readFile('image-compressor-sample-camera-photo.jpeg');
const one = () => sharp(src).resize(1600).webp({ quality: 80 }).toBuffer();
await one(); // warm up
const t0 = performance.now();
let next = 0;
async function lane() { while (next < jobs) { next++; await one(); } }
await Promise.all(Array.from({ length: inflight }, lane));
const s = (performance.now() - t0) / 1000;
console.log(JSON.stringify({ perSec: jobs / s }));
What did the grid show?
Images per second, with peak resident memory in brackets:
| sharp.concurrency | 1 in flight | 4 in flight | 8 in flight | 16 in flight |
|---|---|---|---|---|
| 1 | 3.8 (185 MB) | 11.0 (235 MB) | 10.5 (237 MB) | 11.3 (235 MB) |
| 2 | 4.1 (165 MB) | 16.0 (245 MB) | 15.6 (255 MB) | 14.8 (252 MB) |
| 4 | 4.2 (169 MB) | 16.3 (280 MB) | 16.3 (266 MB) | 16.2 (276 MB) |
| 8 | 3.8 (171 MB) | 16.2 (306 MB) | 16.6 (301 MB) | 16.5 (304 MB) |
- One job at a time ignores the thread count. The column spans 3.8 to 4.2 per second, a difference I would not trust from 5 runs. I did not dig into why.
- Parallel jobs are where the speedup is. At concurrency 4, going from 1 job in flight to 4 took throughput from 4.2 to 16.3 per second, 3.9 times.
- Concurrency 2 already reaches the plateau. With 4 in flight it gave 16.0 per second, against 16.3 at concurrency 4 and 16.2 at 8.
- More in flight than 4 bought nothing. At concurrency 4 the cells at 4, 8 and 16 in flight are 16.3, 16.3 and 16.2.
- Memory climbs with both settings. The lowest peak with parallel work was 235 MB (concurrency 1, 4 in flight). Concurrency 8 with 4 in flight used 306 MB, against 245 MB at concurrency 2, for the same 16 per second. That is 61 MB for nothing.
Note: do not stop at concurrency 1 to save memory. Four jobs in flight gave 11.0 per second there, against 16.0 at concurrency 2 for 10 MB more. On a small host, concurrency 2 with 4 jobs is the cheapest point I measured that reached the plateau.
What should you do?
- Start with 2 threads per job and 4 jobs in flight, then raise one number at a time and watch throughput.
- Do not raise
sharp.concurrency()hoping for a speedup on a single request. It did nothing for a lone job here. - Put a bound on jobs in flight. A
Promise.allover 10,000 files is how you get the 16-in-flight column and a memory graph that looks like a hill. My batch CLI with bounded concurrency shows a small loop that does this. - Turn
sharp.cache(false)on in benchmarks. The docs list the defaults as 50 MB of memory, 20 open files and 100 cached operations; I disabled it so repeat runs could not reuse work. - Check your own machine. The grid will differ on a 2-core container.
The Blinkimg API takes this bookkeeping off your server if you would rather post a file and get one back. How we time things on the site is on the how we measure page.
How I measured
- Machine: Apple M1 Pro, 8 cores, 16 GB, macOS, 2026-10-18. Default
sharp.concurrency()read 6. - Versions: Node 24.22.0, sharp 0.35.4, libvips 8.18.6.
- Input:
apps/web/public/images/index/image-compressor-sample-camera-photo.jpeg, 4964 × 2782, read once into a Buffer. - Job:
resize(1600).webp({ quality: 80 }), 40 jobs per run, one warm-up job excluded, median of 5 fresh processes per cell. - Peak memory: maximum resident set size from
/usr/bin/time -l, median of the same 5 runs. Raw output inmeasured.json.
What I did not test
Other formats (AVIF encode is far slower and may scale differently), Linux, containers with CPU limits, a concurrency of 6 (the machine default) or 3, and a mix of image sizes. I also did not change Node's libuv thread pool size.
I build Blinkimg, an image compressor and converter with a developer API. I wrote this article with help from an AI assistant (Claude), which ran the code on my machine; every number in it comes from those runs.

Top comments (0)