[rust-dev] Runtime cost of Option
Hi all, Does using Option incur a runtime cost (like increased memory usage) compared to a hypothetical case if Rust had a NULL type in the language? Or does it get optimized away, such that it is akin to using NULL in the first place (albeit safer of course)? I have not looked at any assemblies, ut my intuition says that a comparison with None is a single-word check, so it should be pretty fast. Thanks -- Ziad ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
Re: [rust-dev] Runtime cost of Option
Q patch just recently landed to do that optimization for Option types containing a pointer. Options wrapping a value type still need an extra word however in order to distinguish between the Some/None cases though. On Wednesday, May 29, 2013, Ziad Hatahet wrote: Hi all, Does using Option incur a runtime cost (like increased memory usage) compared to a hypothetical case if Rust had a NULL type in the language? Or does it get optimized away, such that it is akin to using NULL in the first place (albeit safer of course)? I have not looked at any assemblies, ut my intuition says that a comparison with None is a single-word check, so it should be pretty fast. Thanks -- Ziad ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
Re: [rust-dev] Runtime cost of Option
On Wed, May 29, 2013 at 1:53 PM, Ziad Hatahet hata...@gmail.com wrote: Hi all, Does using Option incur a runtime cost (like increased memory usage) compared to a hypothetical case if Rust had a NULL type in the language? Or does it get optimized away, such that it is akin to using NULL in the first place (albeit safer of course)? I have not looked at any assemblies, ut my intuition says that a comparison with None is a single-word check, so it should be pretty fast. Thanks -- Ziad Any enum with a non-nullable pointer type (~T, @T, T, ~[T], @[T], ~str, @str) and second zero-size variant is optimized to a nullable pointer now. The optimization still needs to be extended to slices though (they're two words, but the enum could also be 2 words, not 3). ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
Re: [rust-dev] Runtime cost of Option
You will find some more informations in this recent Stackoverflow question : http://stackoverflow.com/q/16504643/112053 Le mercredi 29 mai 2013 10:53:41 Ziad Hatahet a écrit : Hi all, Does using Option incur a runtime cost (like increased memory usage) compared to a hypothetical case if Rust had a NULL type in the language? Or does it get optimized away, such that it is akin to using NULL in the first place (albeit safer of course)? I have not looked at any assemblies, ut my intuition says that a comparison with None is a single-word check, so it should be pretty fast. Thanks -- Ziad ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev