From f779e13bc806243767e561e4a1aeb645bd9ab373 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Mon, 24 May 2021 12:50:48 +0100 Subject: [PATCH] Remove SIMD for now (#1025) This is by no means a proper fix, but Chrome 91 (stable tomorrow) brings some breaking changes to SIMD, and I'd rather disable SIMD for now to avoid breaking Squoosh altogether once it hits stable, and work on a proper fix in a separate branch. --- src/features/encoders/jxl/worker/jxlEncode.ts | 13 +----- .../encoders/webP/worker/webpEncode.ts | 6 --- src/features/encoders/wp2/worker/wp2Encode.ts | 13 +----- src/sw/to-cache.ts | 44 +++---------------- 4 files changed, 7 insertions(+), 69 deletions(-) diff --git a/src/features/encoders/jxl/worker/jxlEncode.ts b/src/features/encoders/jxl/worker/jxlEncode.ts index 0378c2a7..40d71680 100644 --- a/src/features/encoders/jxl/worker/jxlEncode.ts +++ b/src/features/encoders/jxl/worker/jxlEncode.ts @@ -14,28 +14,17 @@ import type { JXLModule } from 'codecs/jxl/enc/jxl_enc'; import type { EncodeOptions } from '../shared/meta'; import { initEmscriptenModule } from 'features/worker-utils'; -import { threads, simd } from 'wasm-feature-detect'; +import { threads } from 'wasm-feature-detect'; import wasmUrl from 'url:codecs/jxl/enc/jxl_enc.wasm'; import wasmUrlWithMT from 'url:codecs/jxl/enc/jxl_enc_mt.wasm'; import workerUrl from 'omt:codecs/jxl/enc/jxl_enc_mt.worker.js'; -import wasmUrlWithMTAndSIMD from 'url:codecs/jxl/enc/jxl_enc_mt_simd.wasm'; -import workerUrlWithSIMD from 'omt:codecs/jxl/enc/jxl_enc_mt_simd.worker.js'; - let emscriptenModule: Promise; async function init() { if (await threads()) { - if (await simd()) { - const jxlEncoder = await import('codecs/jxl/enc/jxl_enc_mt_simd'); - return initEmscriptenModule( - jxlEncoder.default, - wasmUrlWithMTAndSIMD, - workerUrlWithSIMD, - ); - } const jxlEncoder = await import('codecs/jxl/enc/jxl_enc_mt'); return initEmscriptenModule(jxlEncoder.default, wasmUrlWithMT, workerUrl); } diff --git a/src/features/encoders/webP/worker/webpEncode.ts b/src/features/encoders/webP/worker/webpEncode.ts index 035c166d..1b026dd9 100644 --- a/src/features/encoders/webP/worker/webpEncode.ts +++ b/src/features/encoders/webP/worker/webpEncode.ts @@ -14,18 +14,12 @@ import type { WebPModule } from 'codecs/webp/enc/webp_enc'; import type { EncodeOptions } from '../shared/meta'; import { initEmscriptenModule } from 'features/worker-utils'; -import { simd } from 'wasm-feature-detect'; import wasmUrl from 'url:codecs/webp/enc/webp_enc.wasm'; -import wasmUrlWithSIMD from 'url:codecs/webp/enc/webp_enc_simd.wasm'; let emscriptenModule: Promise; async function init() { - if (await simd()) { - const webpEncoder = await import('codecs/webp/enc/webp_enc_simd'); - return initEmscriptenModule(webpEncoder.default, wasmUrlWithSIMD); - } const webpEncoder = await import('codecs/webp/enc/webp_enc'); return initEmscriptenModule(webpEncoder.default, wasmUrl); } diff --git a/src/features/encoders/wp2/worker/wp2Encode.ts b/src/features/encoders/wp2/worker/wp2Encode.ts index 1c12573b..f59478b1 100644 --- a/src/features/encoders/wp2/worker/wp2Encode.ts +++ b/src/features/encoders/wp2/worker/wp2Encode.ts @@ -14,28 +14,17 @@ import type { WP2Module } from 'codecs/wp2/enc/wp2_enc'; import type { EncodeOptions } from '../shared/meta'; import { initEmscriptenModule } from 'features/worker-utils'; -import { threads, simd } from 'wasm-feature-detect'; +import { threads } from 'wasm-feature-detect'; import wasmUrl from 'url:codecs/wp2/enc/wp2_enc.wasm'; import wasmUrlWithMT from 'url:codecs/wp2/enc/wp2_enc_mt.wasm'; import workerUrl from 'omt:codecs/wp2/enc/wp2_enc_mt.worker.js'; -import wasmUrlWithMTAndSIMD from 'url:codecs/wp2/enc/wp2_enc_mt_simd.wasm'; -import workerUrlWithSIMD from 'omt:codecs/wp2/enc/wp2_enc_mt_simd.worker.js'; - let emscriptenModule: Promise; async function init() { if (await threads()) { - if (await simd()) { - const wp2Encoder = await import('codecs/wp2/enc/wp2_enc_mt_simd'); - return initEmscriptenModule( - wp2Encoder.default, - wasmUrlWithMTAndSIMD, - workerUrlWithSIMD, - ); - } const wp2Encoder = await import('codecs/wp2/enc/wp2_enc_mt'); return initEmscriptenModule(wp2Encoder.default, wasmUrlWithMT, workerUrl); } diff --git a/src/sw/to-cache.ts b/src/sw/to-cache.ts index cbc922f5..dace22e2 100644 --- a/src/sw/to-cache.ts +++ b/src/sw/to-cache.ts @@ -1,4 +1,4 @@ -import { threads, simd } from 'wasm-feature-detect'; +import { threads } from 'wasm-feature-detect'; import webpDataUrl from 'data-url:./tiny.webp'; import avifDataUrl from 'data-url:./tiny.avif'; @@ -75,9 +75,6 @@ import avifEncWasm from 'url:codecs/avif/enc/avif_enc.wasm'; import * as avifEnc from 'entry-data:codecs/avif/enc/avif_enc.js'; // JXL -import * as jxlEncMtSimdWorker from 'entry-data:codecs/jxl/enc/jxl_enc_mt_simd.worker.js'; -import * as jxlEncMtSimd from 'entry-data:codecs/jxl/enc/jxl_enc_mt_simd'; -import jxlEncMtSimdWasm from 'url:codecs/jxl/enc/jxl_enc_mt_simd.wasm'; import * as jxlEncMtWorker from 'entry-data:codecs/jxl/enc/jxl_enc_mt.worker.js'; import * as jxlEncMt from 'entry-data:codecs/jxl/enc/jxl_enc_mt'; import jxlEncMtWasm from 'url:codecs/jxl/enc/jxl_enc_mt.wasm'; @@ -89,15 +86,10 @@ import oxiMtWasm from 'url:codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm'; import oxiWasm from 'url:codecs/oxipng/pkg/squoosh_oxipng_bg.wasm'; // WebP -import * as webpEncSimd from 'entry-data:codecs/webp/enc/webp_enc_simd'; -import webpEncSimdWasm from 'url:codecs/webp/enc/webp_enc_simd.wasm'; import * as webpEnc from 'entry-data:codecs/webp/enc/webp_enc'; import webpEncWasm from 'url:codecs/webp/enc/webp_enc.wasm'; // WP2 -import * as wp2EncMtSimdWorker from 'entry-data:codecs/wp2/enc/wp2_enc_mt_simd.worker.js'; -import * as wp2EncMtSimd from 'entry-data:codecs/wp2/enc/wp2_enc_mt_simd'; -import wp2EncMtSimdWasm from 'url:codecs/wp2/enc/wp2_enc_mt_simd.wasm'; import * as wp2EncMtWorker from 'entry-data:codecs/wp2/enc/wp2_enc_mt.worker.js'; import * as wp2EncMt from 'entry-data:codecs/wp2/enc/wp2_enc_mt'; import wp2EncMtWasm from 'url:codecs/wp2/enc/wp2_enc_mt.wasm'; @@ -105,14 +97,8 @@ import * as wp2Enc from 'entry-data:codecs/wp2/enc/wp2_enc'; import wp2EncWasm from 'url:codecs/wp2/enc/wp2_enc.wasm'; export const theRest = (async () => { - const [ - supportsThreads, - supportsSimd, - supportsWebP, - supportsAvif, - ] = await Promise.all([ + const [supportsThreads, supportsWebP, supportsAvif] = await Promise.all([ threads(), - simd(), ...[webpDataUrl, avifDataUrl].map(async (dataUrl) => { if (!self.createImageBitmap) return false; const response = await fetch(dataUrl); @@ -153,15 +139,7 @@ export const theRest = (async () => { } // JXL - if (supportsThreads && supportsSimd) { - items.push( - jxlEncMtSimdWorker.main, - ...jxlEncMtSimdWorker.deps, - jxlEncMtSimd.main, - ...jxlEncMtSimd.deps, - jxlEncMtSimdWasm, - ); - } else if (supportsThreads) { + if (supportsThreads) { items.push( jxlEncMtWorker.main, ...jxlEncMtWorker.deps, @@ -181,22 +159,10 @@ export const theRest = (async () => { } // WebP - if (supportsSimd) { - items.push(webpEncSimd.main, ...webpEncSimd.deps, webpEncSimdWasm); - } else { - items.push(webpEnc.main, ...webpEnc.deps, webpEncWasm); - } + items.push(webpEnc.main, ...webpEnc.deps, webpEncWasm); // WP2 - if (supportsThreads && supportsSimd) { - items.push( - wp2EncMtSimdWorker.main, - ...wp2EncMtSimdWorker.deps, - wp2EncMtSimd.main, - ...wp2EncMtSimd.deps, - wp2EncMtSimdWasm, - ); - } else if (supportsThreads) { + if (supportsThreads) { items.push( wp2EncMtWorker.main, ...wp2EncMtWorker.deps,