Anonymous
10/13/2025, 1:39:45 PM
No.106873492
>>106873424
Yeah but if you don't write sloppy code that creates these pathological cases then it's not an issue.
FWIW in my C++ code bounds checks are always on (yes, even in release mode) for my Span type and I even have a helper that does safety checking for casts. Modern CPUs are insanely fast and they handle branches that are never taken really well. Compilers are also smart (sometimes too smart, you could argue) so very often the bounds check will be eliminated anyway. The benefits outweigh the miniscule cost most of the time. Rust 100% made the right call in that regard.
You might want to disable this kind of stuff in only the innermost hottest loop (after thorough verification that your code is actually correct and doesn't have bugs), but other than that you definitely always want it on.
Yeah but if you don't write sloppy code that creates these pathological cases then it's not an issue.
FWIW in my C++ code bounds checks are always on (yes, even in release mode) for my Span type and I even have a helper that does safety checking for casts. Modern CPUs are insanely fast and they handle branches that are never taken really well. Compilers are also smart (sometimes too smart, you could argue) so very often the bounds check will be eliminated anyway. The benefits outweigh the miniscule cost most of the time. Rust 100% made the right call in that regard.
You might want to disable this kind of stuff in only the innermost hottest loop (after thorough verification that your code is actually correct and doesn't have bugs), but other than that you definitely always want it on.