top | item 46627889

(no title)

esjeon | 1 month ago

Theoretically, C is likely faster than Rust only by an unnoticeably small margin. Still, this is unavoidable because Rust works with abstraction that (1) adds overhead per-se albeit tiny (2) forces overhead in the design level.

Practically, that little margin can be removed thru a series of engineering, as both are proper system-level programming languages, which offer tight control over the generated machine code. That is, this whole discussion is basically pointless if we mix in engineering factors.

We better talk about overall engineering costs, and personally I think Rust would not overshoot C easily, mainly due to the limitations that Rust puts on the higher level designs.

discuss

order

steveklabnik|1 month ago

What abstraction do you refer to?

esjeon|1 month ago

Rust is actually few steps above from the bare metal, to enforce its security invariants. Boundary checks (which breaks auto-vectorization of loops), stack probe, fat pointer (wastes register), fixed index type (uint), etc.

There are other hidden costs coming from usage of std. Even `Result` is a bit of inefficiency.

I'm not saying any of these are bad. I'm just saying Rust would be slower than C if *naively* used.