-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimized ABI for Option<u32>
and other 32-bit primitives
#4183
Optimized ABI for Option<u32>
and other 32-bit primitives
#4183
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does make sense to me, I'm just asking myself why this wasn't considered before.
I'm definitely interested in reviewing this, but I will have to do some digging and see if there is any historical context around this.
Maybe they didn't like the weird ABI? Otherwise, float to integer conversion could have scared them away, because they can be tricky. In particular, I haven't looked up whether the code I wrote for going f64 (ABI) -> i32/u32/f32 behaves the same way as what the WebAssembly API normally does for us. I will have to look up the spec for that some time.
Thank you for doing this! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was briefly mentioned by alexcrichton in #630 (comment), not sure why it wasn't picked up.
AFAIU this should work just fine, so lets go ahead with this!
Okay, I think this PR is pretty much ready. Aside from the 32-bit primitives, I also had to enable this optimization for For debugging purposes, I also added a new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of nits, but LGTM.
The debugging improvement is amazing as well!
I didn't get what you are trying to say here. In any case, it all looks correct to me. |
Co-authored-by: daxpedda <daxpedda@gmail.com>
Co-authored-by: daxpedda <daxpedda@gmail.com>
Something (I didn't look into it) in the code base assumes that |
Ah, I see! |
This is a PoC to optimize the ABI of
Option<u32>
(another other 32-bit primitives) by usingf64
.The basic idea is that we can avoid going through "main memory" by using
f64
.f64
is large enough to represent all possible values of 32-bit primitives and a hole forNone
. In this case, I used 232+1 for the hole, because it cannot be represented by any of the 32-bit primitives (evenf32
can't represent it exactly). I then use the same sentinel trick wasm bindgen already uses forOption<u16>
and other primitives with <32 bit. So please think of this PR as an extension of that trick.The current state of this PR is just a PoC. It works, but I haven't tested it a lot. I would like to know whether this is something the wasm bindgen people are interested in before polishing it some more.