Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage on Cloudflare Worker #2

Closed
chocolatkey opened this issue Sep 20, 2020 · 8 comments
Closed

Usage on Cloudflare Worker #2

chocolatkey opened this issue Sep 20, 2020 · 8 comments
Labels
blocked-upstream-dependency Upstream dependency needs to be updated enhancement New feature or request

Comments

@chocolatkey
Copy link

Hello,

This is a cool project, and I was thinking of using it in Cloudflare Workers and saw your card here https://github.com/kleisauke/wasm-vips/projects/1#card-44661973
There's a hurdle, however, that prevents this from being possible: "The module and script together must be under 1MB after gzip compression" - https://community.cloudflare.com/t/what-is-the-maximum-allowed-size-of-a-webassembly-module/66453/2

The .wasm file is ~4.3 MB uncompressed, and ~1.41MB (gzip 9) compressed. Maybe a slimmed version of the library could still be used, with some support for formats dropped?

@wis
Copy link

wis commented Oct 9, 2020

execution time is an issue too, you would easily hit the 50 millisecond CPU execution time limit (Workers Bundled plan, free-tier is 10ms) for trivial tasks/operations.

judging by the Speed and memory use from libvips' Wiki, memory consumption is not an issue for using libvips in Workers unlike alternative/competing libraries (33MB is under the 128MB memory limit), however 520ms/(50ms+) CPU execution time is (if you can't use Workers Unbound):
speed2-fs8

@yamiteru
Copy link

Workers unbound is still pretty cheap so no problem with that. I think it has a lot of potential.

@kleisauke
Copy link
Owner

kleisauke commented May 11, 2021

I still need to investigate whether this project can be supported on Cloudflare Workers, but note that this is being done on best effort. vips.wasm is now around 4.74 MB when compiling with -O3 (and 3.98 MB w/o SIMD support). A possible way to slim down the WebAssembly output is to compile it with -Oz instead of -O3.

export CFLAGS="-O3 -fno-rtti -fno-exceptions -mnontrapping-fptoint"

export LDFLAGS="-L$TARGET/lib -O3"

And to disable unnecessary loaders/savers via libvips' configure flags:

wasm-vips/build.sh

Lines 313 to 315 in 71ee394

emconfigure ./autogen.sh --host=$CHOST --prefix=$TARGET --enable-static --disable-shared --disable-dependency-tracking \
--disable-debug --disable-introspection --disable-deprecated --disable-modules --with-radiance --with-analyze --with-ppm \
--with-nsgif --with-lcms --with-zlib --with-libexif --with-jpeg --with-libspng --with-png --with-tiff --with-libwebp \

That said, it seems that Cloudflare maintains a "no background threads" policy because of the potential for Spectre attacks, which could cause problems with wasm-vips as it requires the SharedArrayBuffer API to be available (for V8, an additional argument, --experimental-wasm-threads, must be specified for this). AFAIK, there's no workaround for this since libvips requires threading functionality to be available.

@smashah
Copy link

smashah commented Nov 18, 2021

Please sign up to Larger script sizes for CFW here:

https://www.cloudflare.com/larger-scripts-on-workers-early-access/

@kleisauke
Copy link
Owner

kleisauke commented Jul 18, 2022

wasm-vips in its current form can never run on Cloudflare workers (unfortunately), see the explanation at: https://github.com/kleisauke/cf-worker-wasm-vips#readme

Hopefully this will no longer be an issue when WebAssembly standardizes its https://github.com/WebAssembly/shared-everything-threads proposal. Or alternatively, when Cloudflare workers supports the Web Workers API, allowing WebAssembly memory to be shared between workers (via postMessage()'s).

@kleisauke kleisauke added the blocked-upstream-dependency Upstream dependency needs to be updated label Jul 18, 2022
@sixers
Copy link

sixers commented Jan 3, 2023

Hey, is there any update on this issue?

@kleisauke
Copy link
Owner

Hey, is there any update on this issue?

@sixers No updates, comment #2 (comment) is still relevant at the time of writing (and I do not expect a resolution soon). Issue #18 might also be relevant here.

@kleisauke
Copy link
Owner

Cloudflare has updated its documentation to mention that neither threading nor the Web Workers API is supported:
https://developers.cloudflare.com/workers/platform/web-assembly/#threading

Given that libvips requires threading functionality to be available, I'll close this as "won't fix" for now.

@kleisauke kleisauke closed this as not planned Won't fix, can't repro, duplicate, stale May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked-upstream-dependency Upstream dependency needs to be updated enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants
@sixers @smashah @wis @kleisauke @chocolatkey @yamiteru and others