News for hackers. Stuff that matters.
Re:PartialExecuter: Reducing WebAssembly size by exploring a... by JoshTriplett on Tuesday March 15, 2022 @12:35PM (#30687406)
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 a... by carlopi on Tuesday March 15, 2022 @01:22PM (#30688105)
Thanks a lot!

I also believe it would be cool to upstream this, we will have to sit down and do some planning.

Compilation time could improve (I was actually working on this today), but it's already in line with other optimizations, taking < 10% of the time spent doing optimizations on a big codebase we use as benchmark.

Currently it's applied to all functions, since runtime it's anyhow somehow linear in the number of Instructions a Function has, but possibly in more costly versions of this (that we have on paper but yet to implement) some logic to filter functions in advance could be used.

Re:PartialExecuter: Reducing WebAssembly size by exploring a... by JoshTriplett on Tuesday March 15, 2022 @03:51PM (#30690558)
When upstreaming it, it might make sense to give it two mechanisms: either process every function, or process only functions labeled to use it. Then, a frontend can experiment with things like automatically detecting which functions would benefit from it, using language-specific mechanisms. Or, worst-case, frontends can provide attributes to tag functions explicitly, and libraries can tag functions known to benefit from this.
Re:PartialExecuter: Reducing WebAssembly size by exploring a... by saagarjha on Tuesday March 15, 2022 @06:03PM (#30692444)
My understanding is that CheerpX, but simulating a full userspace, can optimize all the way through system libraries, which are typically very general and have lots of code that is “dead” to your application. How would this approach fail for applications where the code tends to be more specific to the task?
Re:PartialExecuter: Reducing WebAssembly size by exploring a... by astrange on Wednesday March 16, 2022 @12:31AM (#30695339)
Seeing through system libraries sounds problematic already, since some of them like libc violate aliasing when you can see their implementations, even in LLVM byte code form.
Re:PartialExecuter: Reducing WebAssembly size by exploring a... by carlopi on Thursday March 17, 2022 @05:29AM (#30709227)
I have to double check this, but the approach should be theoretically sound since we are quite strict with what functions are considered to have known call-sites: Function has to be internal (as in no visibility from outside) + no indirect uses (so no saving a pointer to the function somewhere). This should be enough to solve the problem you are thinking about.
Re:PartialExecuter: Reducing WebAssembly size by exploring a... by saagarjha on Wednesday March 16, 2022 @06:28AM (#30697130)
That's actually a good point–more aggressive optimizations that peek through libraries that are not typically visible to the compiler are generally going to break things like allocators. Although, I guess something must be compiling them anyways, so perhaps it might end up OK?
Re:PartialExecuter: Reducing WebAssembly size by exploring a... by namibj on Tuesday March 15, 2022 @11:35PM (#30695043)
Consider integrating with PGO there, at least for getting most of the gains (assuming they are about performance, not binary size) with a fraction of the cost.
Re:PartialExecuter: Reducing WebAssembly size by exploring a... by masklinn on Tuesday March 15, 2022 @12:45PM (#30687547)
> 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 a... by carlopi on Tuesday March 15, 2022 @01:27PM (#30688181)
PartialExecuter happens at the LLVM's IR level, and in theory it's fully generic. Then has been only partially tested outside the Cheerp-pipeline, so I would expect it to rely on some implicit assumptions on the kind of legalizations or lowering that are done before-hand.

Target-wise, all information is kept encoded in the IR, so that part is easier (the only strange thing that might happens is bumping some alignment to 8, but I expect every target to be able to handle the prescribed IR alignemtn)

Re:PartialExecuter: Reducing WebAssembly size by exploring a... by syrusakbary on Tuesday March 15, 2022 @12:53PM (#30687667)
I'd love if the is pass submitted upstream as well if possible. I think a lot of ecosystems could benefit from the awesome work you did!