You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is it expected that mozjpeg: true uses significantly more cpu? #4603
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this question
TODO
Please provide sample image(s) that help explain this question
2,149 JPEGs tested with MozJPEG on and off at quality 75 with concurrency of 8 on MacBook M3 Pro.
CPU averages use each image’s median of three runs on an M3 Pro, including decode/rotate/resize/encode. Ratios average each image’s input KB ÷ output KB; higher means greater size reduction. Smaller images weren’t enlarged.
Requested width
Average CPU (ms)
CPU saved
Average output KB
Average input/output ratio
3840
31.67 → 8.80
72.2%
39.57 → 51.81
4.13 → 3.81
1920
20.96 → 7.72
63.2%
25.90 → 33.52
4.51 → 4.09
1080
14.48 → 5.76
60.2%
17.71 → 22.71
5.62 → 4.93
640
11.01 → 5.02
54.4%
12.76 → 16.31
8.31 → 7.09
Disabling MozJPEG saved 54–72% CPU, with average outputs 28–31% larger.
Yes, I enabled mozjpeg in vercel/next.js#65846 to ensure feature-parity with squoosh, which always used mozjpeg.
If CPU cost is now of more concern than bandwidth then either switch off mozjpeg or perhaps look at selectively disabling optimiseScans (whilst keeping mozjpeg enabled).
Thanks! I tried with both mozjpeg: true and optimizeScans: false and there was some improvement so that might be a good compromise since there's barely a size increase.
Width
Average CPU (ms)
CPU saved
Average output KB
Size increase
3840
32.03 → 23.76
25.8%
39.57 → 41.29
4.3%
1920
21.24 → 16.46
22.5%
25.90 → 26.82
3.6%
1080
14.66 → 11.60
20.8%
17.71 → 18.35
3.6%
640
11.18 → 9.13
18.4%
12.76 → 13.22
3.6%
It looks like mozjpeg sets about 5 different settings so I might have to try to benchmark all the combinations.
The thing to note about squoosh was that we always used sharp for production builds (next build) and squoosh was only used for development builds (next dev). Now of course, sharp is used for both.
I'm tempted to just turn of mozjpeg completely since it seems like no one noticed the difference between on vs off.
How did you decide the default settings for sharp?
How did you decide the default settings for sharp?
The default is all mozjeg features off, which is the same as using libjpeg-turbo (upon which mozjpeg is based), as that's what sharp provided for many years.
Switching mozjpeg on is syntactic sugar to set all the mozjpeg-related options to their mozjpeg defaults:
Activity
lovell commentedon Sep 11, 2026
Yes, I enabled mozjpeg in vercel/next.js#65846 to ensure feature-parity with squoosh, which always used mozjpeg.
If CPU cost is now of more concern than bandwidth then either switch off mozjpeg or perhaps look at selectively disabling
optimiseScans(whilst keeping mozjpeg enabled).feat(next/image): Add experimental imgOptMozjpeg config (#98571)
styfle commentedon Sep 11, 2026
Thanks! I tried with both
mozjpeg: trueandoptimizeScans: falseand there was some improvement so that might be a good compromise since there's barely a size increase.It looks like mozjpeg sets about 5 different settings so I might have to try to benchmark all the combinations.
The thing to note about squoosh was that we always used sharp for production builds (next build) and squoosh was only used for development builds (next dev). Now of course, sharp is used for both.
I'm tempted to just turn of mozjpeg completely since it seems like no one noticed the difference between on vs off.
How did you decide the default settings for sharp?
lovell commentedon Sep 13, 2026
The default is all mozjeg features off, which is the same as using libjpeg-turbo (upon which mozjpeg is based), as that's what sharp provided for many years.
Switching mozjpeg on is syntactic sugar to set all the mozjpeg-related options to their mozjpeg defaults:
sharp/lib/output.mjs
Lines 637 to 643 in 9dcb3dd
lovell commentedon Nov 28, 2026
v0.35.6 now available, thanks for the PR to improve the docs.