Does WASM use some sort of RTL compression for the data segment?

42 views
Skip to first unread message

Floh

unread,
Jun 20, 2020, 4:42:54 PM6/20/20
to emscripten-discuss
I just noticed something interesting... through a stupid mistake on my part I accidentally added 4 MBytes of bloat to my native-compiled executables, because I statically initialized some innocent looking members of a very big global struct variable (so that this global struct only had a handful items initialized to non-zero values, but the remaining 4 MBytes were all zeros).

Interestingly, the (uncompressed) WASM version *wasn't* 4 MByte, instead it was about the same size as if that massive global variable would be in the BSS segment (that's why I didn't notice the bloat in the native executables, I always check the size of the WASM output very carefully, but not for the native builds).

So my question: Does WASM have some sort of simple compression for the data segment which kicks in for large chunks of zeroes? I tried to search the available WASM info, but couldn't find anything "obvious"...

Thanks!
-Floh.

Thomas Lively

unread,
Jun 20, 2020, 5:04:02 PM6/20/20
to emscripte...@googlegroups.com
WebAssembly itself doesn't have any compression in its data segments, but Binaryen does split up data segments around ranges of zeroes as an optimization. That transformation depends on the memory being initialized to zero when it is created, making zeroes in data sections redundant.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/756dcbba-a40f-4f78-af79-74aa46df7625o%40googlegroups.com.

Floh

unread,
Jun 20, 2020, 5:09:29 PM6/20/20
to emscripten-discuss
Ah so it's a Binaryen thing, not clang's WASM backend. Good to know :)

Thanks!

On Saturday, 20 June 2020 23:04:02 UTC+2, Thomas Lively wrote:
WebAssembly itself doesn't have any compression in its data segments, but Binaryen does split up data segments around ranges of zeroes as an optimization. That transformation depends on the memory being initialized to zero when it is created, making zeroes in data sections redundant.

On Sat, Jun 20, 2020 at 1:42 PM Floh <flo...@gmail.com> wrote:
I just noticed something interesting... through a stupid mistake on my part I accidentally added 4 MBytes of bloat to my native-compiled executables, because I statically initialized some innocent looking members of a very big global struct variable (so that this global struct only had a handful items initialized to non-zero values, but the remaining 4 MBytes were all zeros).

Interestingly, the (uncompressed) WASM version *wasn't* 4 MByte, instead it was about the same size as if that massive global variable would be in the BSS segment (that's why I didn't notice the bloat in the native executables, I always check the size of the WASM output very carefully, but not for the native builds).

So my question: Does WASM have some sort of simple compression for the data segment which kicks in for large chunks of zeroes? I tried to search the available WASM info, but couldn't find anything "obvious"...

Thanks!
-Floh.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages