← Back to context

Comment by yefol

7 hours ago

Not him, but projects that need performance often use unsafe or otherwise allow for UB. Embedded is arguably another example, since no_std allows UB even without unsafe, for instance by causing a stack overflow.

> for instance by causing a stack overflow

That's not "for instance", that's literally the only place Rust has unfixable UB on embedded (code on OS has other such things, e.g. reading/writing to `/proc/self/mem`).

> projects that need performance often use unsafe

You'll be surprised to hear how often it's not needed at all. And when it is, you'll be surprised to hear how many times you can still avoid it with some tricks. Contrary to popular belief, performance isn't the most common reason for unsafe (FFI probably is).

I haven't needed `unsafe` for performance since crates like zerocopy etc exist. It's been years, and I've worked hard to shave nanoseconds off of code, using valgrind to measure single digit changes to branch predictions.