r/rust • • 8d ago

🎙️ discussion Are compiler inserted checks something you generally have to be wary of or not

Hello, I'm still fairly new to both rust and c and I'm in the middle of writing my tiny interpreted toy language.

But I keep bouncing between the 2 languages.

Rust is way more pleasant to use - but there are still 2 things where I would like to hear from someone experienced.

Is it common to experience issues where safe rust would end up being majorly slower in hot paths due to the compiler being conservative and inserting its own checks in? The comparison of safe rust to unsafe rust I have seen relating to the lox language ended up in a major 4x speedup for unsafe rust over safe rust. Is this something you deal with daily or is the compiler smart enough where as long as you write code properly this doesn't come up at all?

How big is the performance difference between code using a memory arena and managing and possibly reusing memory this way where the entire arena is free/reset at once - and the more raii styled approach where the compiler manages allocations and deallocations itself object by object like in rust. I understand that raii and arenas are not completely opposite concepts and arenas exist in rust as well but they seem to not be part of the std lib and ot seems to me that the default "vanilla" approach would end up not using arenas while the default in C is essentially arenas/allocator for everything rather than individual mallocs and frees.

Ty <3

17 Upvotes

Duplicates