Live data from Hacker News

PartialExecuter: Reducing WebAssembly size by exploring all executions in LLVM

leaningtech.com

1–10 of 111 posts

PartialExecuter: Reducing WebAssembly size by exploring all executions in LLVM

#1
WebAssembly is commonly used as part of web applications, and minimizing its size is especially important.

As part of the latest release of Cheerp, our C++ to WebAssembly/JavaScript compiler, we have introduced a powerful new LLVM optimization that aggressively reduce WebAssembly output size at compile time.

We have named this optimization 'PartialExecuter', the key idea behind it being taking advantage of known function parameters to find inner code blocks that cannot ever be possibly executed.

Such blocks can then be completely removed from the compiled output, significantly reducing its size.

What makes this pass more powerful than typical Dead Code Elimination is the ability of reasoning over all the possible executions that the code can take, while being robust to memory stores and side-effects. Moreover, PartialExecuter can even reason over loads as far as they refer to read-only memory. This latter capability is especially useful to drop code from complex functions whose behavior depend on input strings (i.e. printf).

We think this work may be of interest for the HN community, and we welcome feedback and questions.

In-depth blog post: https://leaningtech.com/reducing-webassembly-size-by-explori...

PartialExecuter: Reducing WebAssembly size by exploring all executions in LLVM
leaningtech.com

Re: PartialExecuter: Reducing WebAssembly size by exploring all executions in LLVM

#5
This looks great! Please consider upstreaming this into LLVM; it would benefit many other users of LLVM. I'd love to see this used in Rust, for instance.

What kind of compilation performance do you see for how long this pass takes?

Do you apply this to all functions, or to all functions with certain properties, or to functions tagged some particular way?

Re: PartialExecuter: Reducing WebAssembly size by exploring all executions in LLVM

#7
Optimizations like this are incredible to me. In my compiler class in college, I was smitten by how different optimizations were performed, and we only ever worked with pretty basic constant propagation and dead code elimination. The work here is incredible. My respect to the entire team.

Re: PartialExecuter: Reducing WebAssembly size by exploring all executions in LLVM

#8

This looks great! Please consider upstreaming this into LLVM; it would benefit many other users of LLVM. I'd love to see this used in Rust, for instance. What kind of compilation performance do you see for how long this pass takes? Do you apply this to all functions, or to all functions with certain properties, or to functions tagged some particular way?

> This looks great! Please consider upstreaming this into LLVM; it would benefit many other users of LLVM. I'd love to see this used in Rust, for instance.

Or in straight C++ for that matter.

Though possibly the optimisation passes relies on specific properties of the target which don't exist for non-wasm? I didn't see anything in the writeup but that doesn't mean they don't exist.

Re: PartialExecuter: Reducing WebAssembly size by exploring all executions in LLVM

#9
This company has an x86-to-WASM compiler that lets you execute arbitrary binaries in the browser.

Also a JVM to WASM transpiler.

There's a fantastic Meetup presentation given by one of them where they show running a C++ multiplayer game with both client AND server running in a browser, using WebRTC as a networking polyfill. Really mindblowing:

https://youtu.be/7JUs4c99-mo?t=167

Post reply on HN