Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't think the rust team would claim writing idiomatic safe rust code is always zero-overhead. Indexing into an array adds bounds checks which takes non-zero time. So by default you trade-off safety for performance to some degree; but this can be bypassed if needed, that's why you have unsafe.

For completeness, it's 0.1x the size with 1.20x the runtime, so these are not just language differences



I think the phrase is "zero-cost abstractions", meaning "Supposing you want bounds checks, you may as well use ours and not roll your own"


It's true that you can escape them though. There are some other small things (which AFAICT you can escape from to as well)


> Indexing into an array adds bounds checks which takes non-zero time.

* When done in such a way that the compiler cannot know the access is in-bounds. The same code in C would also need to perform bounds checks on access. If you do the same assertion you would in C checking that the indices are always less than the length, then Rust will not perform the bounds check because it detects it's unnecessary. Leveraging iterators is one idiomatic way of avoiding those bounds checks.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: