Comments (3)
In practice, WASM streaming mitigates this, but I can imagine situations where it won't be the definitive band-aid.
from wasm-vips.
Sorry for the delay. A significant portion of the vips.wasm
file size comes from the foreign loaders and savers. A minimal libvips (i.e. with only core functionality) can be configured using this patch:
--- a/build.sh
+++ b/build.sh
@@ -488,11 +488,7 @@ node --version
sed -i "/subdir('man')/{N;N;N;N;d;}" meson.build
meson setup _build --prefix=$TARGET --cross-file=$MESON_CROSS --default-library=static --buildtype=release \
-Ddeprecated=false -Dexamples=false -Dcplusplus=$LIBVIPS_CPP -Dauto_features=disabled \
- ${ENABLE_MODULES:+-Dmodules=enabled} -Dcgif=enabled -Dexif=enabled ${ENABLE_AVIF:+-Dheif=enabled} \
- -Dheif-module=enabled -Dimagequant=enabled -Djpeg=enabled ${ENABLE_JXL:+-Djpeg-xl=enabled} \
- -Djpeg-xl-module=enabled -Dlcms=enabled ${ENABLE_SIMD:+-Dhighway=enabled} ${ENABLE_SVG:+-Dresvg=enabled} \
- -Dresvg-module=enabled -Dspng=enabled -Dtiff=enabled -Dwebp=enabled -Dnsgif=true -Dppm=true -Danalyze=true \
- -Dradiance=true -Dzlib=enabled
+ -Dnsgif=false -Dppm=false -Danalyze=false -Dradiance=false
meson install -C _build --tag runtime,devel
# Emscripten requires linking to side modules to find the necessary symbols to export
module_dir=$(printf '%s\n' $TARGET/lib/vips-modules-* | sort -n | tail -1)
And by compiling with -Oz
instead of -O3
, using:
--- a/build.sh
+++ b/build.sh
@@ -111,7 +111,7 @@ done
export RUSTFLAGS="-Ctarget-feature=+atomics,+bulk-memory,+nontrapping-fptoint"
# Common compiler flags
-COMMON_FLAGS="-O3 -pthread"
+COMMON_FLAGS="-Oz -pthread"
if [ "$LTO" = "true" ]; then
COMMON_FLAGS+=" -flto"
export RUSTFLAGS+=" -Clto -Cembed-bitcode=yes"
With that, I see:
$ ls -lh lib/*.wasm | awk '{print $5,$9}'
2.9M lib/vips-O3.wasm
2.2M lib/vips-Oz.wasm
However, most WebAssembly files are served Brotli-compressed nowadays. In the ideal case, with v0.0.8, this would mean that ~1.5MiB is transferred over the network.
$ brotli node_modules/wasm-vips/lib/vips.wasm --best -v
Compressed [node_modules/wasm-vips/lib/vips.wasm]: 5.388 MiB -> 1.509 MiB in 8.49 sec
(usually the size is ~1.8MiB due to the use of compression level 4, as shown in your screenshot)
Running the same command over the produced WebAssembly binaries above, I see:
$ brotli lib/vips-O{3,z}.wasm --best -v
Compressed [lib/vips-O3.wasm]: 2.872 MiB -> 968.115 KiB in 4.98 sec
Compressed [lib/vips-Oz.wasm]: 2.144 MiB -> 896.830 KiB in 4.26 sec
I think that modularizing every operation within wasm-vips adds unnecessary complexity to the build logic without yielding any significant benefits. We could, however, experiment with making more foreign loaders/savers as dynamic module.
Let's tag this as an enhancement.
from wasm-vips.
Related Issues (20)
- `heifsave` is not defined HOT 3
- `wasm-vips` is unstable on Node `18.14.2+` and `19.4.0+` HOT 11
- Unstable on Deno HOT 2
- Playground feature request: ability to import file from disk HOT 3
- `WasmTrapJSTypeError` while loading an SVG when building with LTO HOT 3
- Docker compilation error HOT 6
- setup wasm-vips for next.js/react HOT 3
- TS types improvements HOT 3
- writeToBuffer increases RSS size till OOMKilled HOT 3
- Not working on deno deploy HOT 1
- ab [vips::Error]: no such operation pdfload_buffer VipsOperation: class "pdfload_buffer" not found HOT 1
- JPEG 2000 Support HOT 2
- Errors with vite HOT 27
- No paths work when reading files (Deno) HOT 2
- Promise remains in pending mode HOT 3
- Error `heifload: ignoring nclx profile` when converting to AVIF and resizing HOT 4
- Add progress information HOT 3
- Error: need to see wasm magic number HOT 1
- Interlace option in jpegsaveBuffer doesn’t seem to work HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wasm-vips.