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

Bump zstd 1.5.0 #26

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Bump zstd 1.5.0 #26

wants to merge 5 commits into from

Conversation

thewtex
Copy link

@thewtex thewtex commented Sep 6, 2023

No description provided.

@donmccurdy
Copy link
Owner

@thewtex thanks for this! I'll need to review the updates here in a bit more detail, and will get to this PR as soon as I can.


```shell
emcc zstddeclib.c -Oz -s EXPORTED_FUNCTIONS="['_ZSTD_decompress', '_ZSTD_findDecompressedSize', '_ZSTD_isError', '_malloc', '_free']" -Wl,--no-entry -s ALLOW_MEMORY_GROWTH=1 -s MALLOC=emmalloc -o zstddec.wasm
base64 -w 0 zstddec.wasm > zstddec.txt
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the -w 0 flag? I don't have that option (macOS Ventura), maybe we have different versions of this utility?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux it prevents newline's

  -w, --wrap=COLS       wrap encoded lines after COLS character (default 76).
                          Use 0 to disable line wrapping

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a note on this in the README.

README.md Outdated
```

```shell
emcc zstddeclib.c -Oz -s EXPORTED_FUNCTIONS="['_ZSTD_decompress', '_ZSTD_findDecompressedSize', '_ZSTD_isError', '_malloc', '_free']" -Wl,--no-entry -s ALLOW_MEMORY_GROWTH=1 -s MALLOC=emmalloc -o zstddec.wasm
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my own learning, what is -Wl,--no-entry? I couldn't find this in the emcc help output.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a standard linking flag for not creating the entry function when the program starts up (what gets called before main). This is usually _start, which is also true for WebAssembly, but we do not need it because we are calling the other functions instead, _ZSTD_decompress, etc.


```shell
emcc zstddeclib.c -Oz -s EXPORTED_FUNCTIONS="['_ZSTD_decompress', '_ZSTD_findDecompressedSize', '_ZSTD_isError', '_malloc', '_free']" -Wl,--no-entry -s ALLOW_MEMORY_GROWTH=1 -s MALLOC=emmalloc -o zstddec.wasm
base64 -w 0 zstddec.wasm > zstddec.txt
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the size of the build is roughly doubled after the update. Any idea what might be the cause of that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not sure why that is case.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this may be a blocker -- I don't know if I can justify updating the dependency with that size difference. Many users of the package are sensitive to bundle size.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed improved flags and also backed down on the version. Here is what I found:

The size of the resulting zstddec.wasm increases in subsequent versions:

1.5.0: 32k
1.5.1: 40k
1.5.5: 52k

package.json Outdated
"require": "./dist/zstddec.cjs",
"default": "./dist/zstddec.modern.js"
},
"main": "dist/zstddec.cjs",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll pull these package.json changes out into another PR, so you don't need to worry about them here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@thewtex
Copy link
Author

thewtex commented Oct 11, 2023

rebased

There is now a single script available, ./create_single_file_decoder.sh
that does the desired work.

Add additional emscripten flags that make explicit our build type and
improve the build. `-DNDEBUG=1` is particularly import for our size.
These flags also removed the need for the wasi shims.
The size of the resulting zstddec.wasm increases in subsequent versions:

1.5.0: 32k
1.5.1: 40k
1.5.5: 52k
@thewtex thewtex marked this pull request as draft October 25, 2023 18:54
@thewtex
Copy link
Author

thewtex commented Oct 25, 2023

Something is wrong with the last commit? The tests are failing:

    ✖ RuntimeError: memory access out of bounds
    --------------------------------------------
      operator: error
      stack: |-
  RuntimeError: memory access out of bounds
  at wasm://wasm/0003fd96:wasm-function[58]:0xe97b
  at wasm://wasm/0003fd96:wasm-function[57]:0xe7d8
  at wasm://wasm/0003fd96:wasm-function[59]:0xeacd
  at ZSTDDecoder.decode (/home/matt/src/zstddec-wasm/dist/zstddec.cjs:47:44)
  at Test.<anonymous> (/home/matt/src/zstddec-wasm/zstddec.test.cjs:17:20)

I cannot seem to reproduce the previous working version without the recent changes. @donmccurdy would you mind please trying the build?

This results in:

  RuntimeError: memory access out of bounds

as discussed in donmccurdy#13.
@thewtex
Copy link
Author

thewtex commented Oct 25, 2023

RuntimeError: memory access out of bounds

As discussed in #13 , this is weirdly unreliably unless -s MALLOC=emmalloc is removed.

@thewtex thewtex marked this pull request as ready for review October 25, 2023 21:06
@thewtex thewtex changed the title Bump zstd 1.5.5 Bump zstd 1.5.0 Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants