-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Optimize Option<f64> and friends with nanboxing #31236
Comments
See also rust-lang/rfcs#1230. |
It's currently legal (as in, nothing says otherwise and thus people rightly assume it's legal) to transmute arbitrary |
What if I want to use NaN tagging in my application? Is that just not gonna happen? |
Similar to This issue should probably go to the rfc repository. |
|
I agree with @oli-obk on both points. Explicit opt-in is probably best here as NaN is a valid "value" for floats. A RFC for adding |
Closing in favor of an RFC. |
Once #5977 has landed, this will open up a few possible optimizations for simple enums.
One such optimization would be
Option<f64>
(and friends). For the moment,size_of<f64>() == 8
whilesize_of<Option<f64>>() == 16
, but I believe that we could get it down to 8 by using nanboxing.The idea of nanboxing is simple. In a 64-bits float, IEEE-754 actually specifies 2^52 - 1 different ways of representing
NaN
. Actual CPUs only use a single, which gives us 2^52 - 2 possible values that we could pick as representations forNone
. SpiderMonkey (and LuaJIT, and others) already uses this trick to hide dynamic type information in 64-bit values. I believe that this would work nicely in Rust, too.The text was updated successfully, but these errors were encountered: