Stream: general

Topic: wasm-encoder Instruction encoding performance


view this post on Zulip Sam Estep (Jan 21 2025 at 17:57):

Hello! Apologies if this is the wrong place for this. I've been using wasm-encoder for various projects for a while, and I kept wondering whether matching on the Instruction had any impact on performance, or if the compiler and/or CPU were smart enough to make it not matter. So today I ran a little experiment: https://github.com/samestep/wasm-encoder-performance

To my surprise, I saw a 30% difference in performance on an example of generating some helper functions that I pulled from one of my projects. Granted, usually the Wasm code being generated isn't quite as static as these helper functions are, but it still seems to me that this performance improvement would be worthwhile.

I'd be happy to make a pull request on wasm-tools with this change, but I wanted to check here first before doing that work, in case people aren't in favor of it or would prefer to discuss the design a bit first. Thoughts?

Benchmarking wasm-encoder against an alternative implementation strategy. - samestep/wasm-encoder-performance

view this post on Zulip Alex Crichton (Jan 21 2025 at 19:49):

I think it'd be quite reasonable to add method along these lines for encoding in addition to the Instruction enum yeah. Historically I've found that it's more-or-less nice to have both since sometimes one makes more sense than the other. I suspect the hard part here might be the invocation of the for_each_instruction macro from wasmparser, but if that can be wrangled I think it'd be great to add function-per-instruction encoding like this

view this post on Zulip Sam Estep (Jan 21 2025 at 19:53):

Makes sense, thanks Alex! I'll start working on a PR, then.


Last updated: Jan 24 2025 at 00:11 UTC