From 78dada9126c8156c2f8fd540be88bb40c342394f Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Mon, 19 Dec 2022 20:04:12 +0000 Subject: [PATCH] Tests: skip mapnik and tensorflow for Docker-run benchmarks Maintainance of mapnik seems to have stalled, no ARM64 support Memory requirements of Tensorflow too high, hangs/crashes on AMD64 --- test/bench/Dockerfile | 4 ++-- test/bench/package.json | 2 +- test/bench/perf.js | 17 ++++++++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/test/bench/Dockerfile b/test/bench/Dockerfile index 2be38f23b..bd9ca91bc 100644 --- a/test/bench/Dockerfile +++ b/test/bench/Dockerfile @@ -9,7 +9,7 @@ RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - RUN apt-get install -y nodejs # Install benchmark dependencies -RUN apt-get install -y imagemagick libmagick++-dev graphicsmagick libmapnik-dev +RUN apt-get install -y imagemagick libmagick++-dev graphicsmagick # Install sharp RUN mkdir /tmp/sharp @@ -17,7 +17,7 @@ RUN cd /tmp && git clone --single-branch --branch $BRANCH https://github.com/lov RUN cd /tmp/sharp && npm install --build-from-source # Install benchmark test -RUN cd /tmp/sharp/test/bench && npm install +RUN cd /tmp/sharp/test/bench && npm install --omit optional RUN cat /etc/os-release | grep VERSION= RUN node -v diff --git a/test/bench/package.json b/test/bench/package.json index ff33b3011..2637678b8 100644 --- a/test/bench/package.json +++ b/test/bench/package.json @@ -10,7 +10,6 @@ "dependencies": { "@squoosh/cli": "0.7.2", "@squoosh/lib": "0.4.0", - "@tensorflow/tfjs-node": "4.1.0", "async": "3.2.4", "benchmark": "2.1.4", "gm": "1.25.0", @@ -19,6 +18,7 @@ "semver": "7.3.8" }, "optionalDependencies": { + "@tensorflow/tfjs-node": "4.1.0", "mapnik": "4.5.9" }, "license": "Apache-2.0", diff --git a/test/bench/perf.js b/test/bench/perf.js index 569b6c648..4492d5412 100644 --- a/test/bench/perf.js +++ b/test/bench/perf.js @@ -7,15 +7,22 @@ const { exec } = require('child_process'); const async = require('async'); const Benchmark = require('benchmark'); +const safeRequire = (name) => { + try { + return require(name); + } catch (err) {} + return null; +}; + // Contenders const sharp = require('../../'); const gm = require('gm'); const imagemagick = require('imagemagick'); -const mapnik = require('mapnik'); +const mapnik = safeRequire('mapnik'); const jimp = require('jimp'); const squoosh = require('@squoosh/lib'); process.env.TF_CPP_MIN_LOG_LEVEL = 1; -const tfjs = require('@tensorflow/tfjs-node'); +const tfjs = safeRequire('@tensorflow/tfjs-node'); const fixtures = require('../fixtures'); @@ -138,7 +145,7 @@ async.series({ } }); // mapnik - jpegSuite.add('mapnik-file-file', { + mapnik && jpegSuite.add('mapnik-file-file', { defer: true, fn: function (deferred) { mapnik.Image.open(fixtures.inputJpg, function (err, img) { @@ -253,7 +260,7 @@ async.series({ } }); // tfjs - jpegSuite.add('tfjs-node-buffer-buffer', { + tfjs && jpegSuite.add('tfjs-node-buffer-buffer', { defer: true, fn: function (deferred) { const decoded = tfjs.node.decodeJpeg(inputJpgBuffer); @@ -677,7 +684,7 @@ async.series({ } }); // mapnik - pngSuite.add('mapnik-file-file', { + mapnik && pngSuite.add('mapnik-file-file', { defer: true, fn: function (deferred) { mapnik.Image.open(fixtures.inputPngAlphaPremultiplicationLarge, function (err, img) {