I have a question about performance over safety in Rust.
I'm a professional C++ video game dev. In game developpement we car about panic and backtrace only in debug or 'debug with optmisation', when we ship we want fastest code possible.
The point is with Rust when a use array like [i32; 4] even in release compilation with cargo I still have a panic when accessing out of bound. So somewhere there is a check if the bound is in correct range, a 'if' branch so...
Is there a way to say Rust don't check i know what i'm doing and if it's crap then let's be crap and remove the branch of the test?
Hi, to get a value in a slice you have get_unchecked it will not check if the index is in bound.
If you use a loop or iterators the branch may be optimized out by the compiler, it will understand you are not making out of bound access and just remove the branch.
If you access multiple values you can also hint the compiler to only make one branch at the beginning and not one for each access.
Note that if you index [i32; 4] with a constant or with a value for which compiler can infer that it falls into the correct range (e.g. i in loop for i in 0..3 { .. }) bound check will be eliminated. You may use no-panic to ensure that bound checks got eliminated.
Yes I saw it in Rust Conf on youtube
Today I just evaluate the language with tiny scenarii and compare it with C and C++ ( mainly with https://godbolt.org/ ) and so far lot of think looks good
I hope the best for the future