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 match
ing 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?
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
Makes sense, thanks Alex! I'll start working on a PR, then.
Last updated: Jan 24 2025 at 00:11 UTC