Skip to content

Commit fc1dcfc

Browse files
matmenclaude
andcommitted
bench: sharp with as many threads as ImageScript
sharp's default concurrency on glibc Linux without jemalloc, like the CI runners', is one thread; ImageScript uses up to 8 where they pay off, so sharp gets the same (min(available parallelism, 8)) and the method says so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BsU2GAqbnFSNaYDBGD1Km2
1 parent 25e9cdb commit fc1dcfc

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

‎bench/libs.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// are ones the library doesn't have.
44
import fs from 'node:fs';
55
import { createRequire } from 'node:module';
6+
import os from 'node:os';
67
import { fileURLToPath } from 'node:url';
78
const require = createRequire(import.meta.url);
89

@@ -11,6 +12,8 @@ const ImageScript = await import(process.env.IMAGESCRIPT === 'local' ? '../dist/
1112
const ImageScriptV1 = require('imagescript-v1');
1213
const { Jimp, ResizeStrategy } = await import('jimp');
1314
const sharp = (await import('sharp')).default;
15+
// (as many threads as ImageScript uses by default: sharp's default on glibc Linux without jemalloc, like CI's, is one)
16+
sharp.concurrency(Math.min(os.availableParallelism(), 8));
1417
const canvas = await import('@napi-rs/canvas');
1518
const imageJS = await import('image-js');
1619
const photon = require('@silvia-odwyer/photon-node');

‎bench/report.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ ${table(Object.keys(results.sizes).map(k => [k, k]), LIBS, (key, lib) => results
152152
- Where the library lets you choose, resizing is bilinear (ImageScript 1 only has nearest neighbor), blurring is
153153
gaussian with a radius or sigma of 5, rotating grows the image to fit. Each library uses its own defaults
154154
otherwise, e.g. its PNG compression level.
155+
- Threads: ImageScript uses worker threads where they pay off (the processors available, at most 8), and sharp gets
156+
as many (\`sharp.concurrency()\`; its default on glibc Linux without jemalloc, like on CI, is one). The other
157+
libraries run on one thread.
155158
- [tinybench](https://github.com/tinylibs/tinybench), at least 1.5 seconds and 3 runs per measurement, every library
156159
in its own process.
157160
- The release workflow runs the benchmark for every release and commits the results, on a GitHub Actions runner;

0 commit comments

Comments
 (0)