In the rare event that you really need that incremental extra performance increase, yes.
In any case, somebody's already proposed syntax sugar for unsafe array access: arr[idx] becomes arr[unsafe idx]. If it turns out that unsafe array access is a really common operation, we already have you covered.
And raw-pointer arithmetic is starting to look like a shoe-in, so if you're writing a very unsafe program, you'll soon be able to define large parts of it using C-style pointers, and just write *(arr+idx) for your array access.
In the rare event that you really need that incremental extra performance increase, yes.
It's not a rare event -- at least not in my world.
I mean, it's a rare event when programming in general, but in the few cases where I reach for a low-level tool like C++ or Rust, it's precisely because I want the highest possible performance. I pretty much never want array bounds checking, except when running in debug mode. Why can't bounds checking be a compile-time setting?
Why can't bounds checking be a compile-time setting?
Because the Rust developers strongly disagree with your evaluation of when bounds-checking is necessary. They believe that most native programs (for example, web browsers and word processors) only need to switch it off in hotpaths, and that the cost of bounds-checks elsewhere is negligible. They recognise the need for unchecked array access (and, as I described above, they are providing and will provide various ergonomic ways to perform an unchecked array access), but they think the choice should be made for each access individually, rather than just saying "I care much more about speed than about safety; no bounds-checks for me, please".
Rust also makes several other small performance trade-offs in favour of safety. For example, you generally need to make use of reference-counted smart pointers (Rc), and dynamically-checked mutation guards (RefCell), to write safe Rust code. If performance is an overwhelming priority, then Rust is not the right tool for the job.
5
u/rime-frost May 12 '15
In the rare event that you really need that incremental extra performance increase, yes.
In any case, somebody's already proposed syntax sugar for unsafe array access:
arr[idx]becomesarr[unsafe idx]. If it turns out that unsafe array access is a really common operation, we already have you covered.And raw-pointer arithmetic is starting to look like a shoe-in, so if you're writing a very unsafe program, you'll soon be able to define large parts of it using C-style pointers, and just write
*(arr+idx)for your array access.