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

Compile Issues / Guide #13

Open
wiedehopf opened this issue Jul 7, 2022 · 1 comment
Open

Compile Issues / Guide #13

wiedehopf opened this issue Jul 7, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@wiedehopf
Copy link

Hello, i wanted to reproduce compilation and ran into 2 issues.

First of all zstd dev branch seems to no longer work with this code, i don't know exactly why.
I'm just using zstd tag 1.5.0. (tags 1.4.8/1.4.9 work as well)
1.5.1 and later gives the following error when loading the js:

Uncaught (in promise) TypeError: WebAssembly.instantiate(): Import #1 module="wasi_snapshot_preview1" error: module is not an object or function

This isn't important as the decompression code shouldn't need the most recent version.

If you get Uncaught RuntimeError: memory access out of bounds, then try compiling without -s MALLOC=emmalloc.
The filesize goes a bit up but i have no clue how to fix this.
This is necessary for me both with emcc 3.1.15 and emcc 1.40.1 (tried that one due to it being from around the time this github project was started).

Used the emscriptend docker image to avoid installing that stuff:
https://hub.docker.com/r/emscripten/emsdk

In newer emcc versions --no-entry needs to be added to the emcc options, but that's pretty straight forward.

This should at least give you a working start point for compiling this.

command line used:

wget https://github.com/facebook/zstd/releases/download/v1.5.0/zstd-1.5.0.tar.gz
tar xf zstd-1.5.0.tar.gz
cd zstd-1.5.0/build/single_file_libs
./combine.sh -r ../../lib -o zstddeclib.c zstddeclib-in.c
docker pull emscripten/emsdk:3.1.15
docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk:3.1.15 emcc zstddeclib.c --no-entry -O3 -s EXPORTED_FUNCTIONS="['_ZSTD_decompress', '_ZSTD_findDecompressedSize', '_ZSTD_isError', '_malloc', '_free']" -s ALLOW_MEMORY_GROWTH=1 -o zstddec.wasm

Depending on your application, consider testing -O3 vs -Oz (O3 optimizes for speed, Oz optimizes for binary size).
Now for the 4016 KB json, compressed to 712KB, the decompression time on my 11th gen Intel laptop processor in Google Chrome under Linux was 20ms vs 28ms decompression time with wasm binary size 48KB vs 35KB.
This is both very quick, so it will probably not matter to most people, but someone might find it useful.

@donmccurdy
Copy link
Owner

Thank you! Great to know about the emscripten docker container, I wasn't aware of that. I'll leave a few more comments in #16 and #3.

@donmccurdy donmccurdy added the documentation Improvements or additions to documentation label Jul 29, 2022
thewtex added a commit to thewtex/zstddec-wasm that referenced this issue Oct 25, 2023
This results in:

  RuntimeError: memory access out of bounds

as discussed in donmccurdy#13.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants