bytecodealliance / bytecodealliance/wasm-tools
Consider replacing the `ValType` enum with an opaque 32-bit integer.
- Dominant language
- Rust
- Stars
- 1.8k
- Forks
- 351
- Avg merge
- 16h 57m
- Merged PRs (30d)
- 38
Description
In https://github.com/bytecodealliance/wasm-tools/pull/2295 the `ValType` enum is going to be inflated from 4 bytes to 8 bytes due to the new representation of `RefType`. Previously `RefType` was `[u8; 3]` and in that PR it's changing to `u32`. There's some benchmarks and discussion of this at https://github.com/bytecodealliance/wasm-tools/pull/2295#issuecomment-3504159080. The tl;dr; is that the idea of having `ValType` and `ValTypePacked` is not going to work because it inevitably leads to runtime conversions between the two which is slower than just having one.
I wanted to open this though to at least record this as an issue. I don't believe that in Rust today the tradeoff of losing `match`-exhaustiveness is worth it. Perhaps in the future this may change (e.g. the speedups are worth it) or maybe some future Rust feature comes along (e.g. pattern types) which enables using `enum` and also having a 4-byte `ValType`. In the meantime though I think 8-byte `ValType` is the best we can do.
Contributor guide
Assessment
This issue has not been assessed yet.