3 ms·
AFAIK, some Rust types are checked at runtime. For example, RefCell: "Because RefCell<T> allows mutable borrows checked at runtime, you can mutate the value in
by jadbox 7y ago
AFAIK, some Rust types are checked at runtime. For example, RefCell:
"Because RefCell<T> allows mutable borrows checked at runtime, you can mutate the value inside the RefCell<T> even when the RefCell<T> is immutable."
*source https://doc.rust-lang.org/book/ch15-05-interior-mutability.html https://doc.rust-lang.org/book/ch15-05-interior-mutability.h...
EDIT: Sorry, I don't mean 'runtime type checks' are slowing down Rust, but rather that Rust performs more general runtime safety checks (like RefCell).
- pknopf 7y agoThat isn't "type checking", that is just a guard to prevent simultaneous writes to the same data.
- jadbox 7y agoYou're correct- what I had meant to say is Rust is smarter with more runtime checks over C for several cases, like RefCell. Therefor, Rust can be slower than C because of safety (but not because of type checking itself).
- pknopf 7y agoRefCell has an internal semaphore. It's used specifically for multi threaded scenarios. If someone is writing a multi threaded C app, they will likely be using semaphores as well. At least, they should be. Rust just enforces it. So, I wouldn't say rust is "slower" in the regard.
- PrototypeNM1 7y agoIirc RefCell is marked !Sync, I thought Mutex was the multithreadong analog?
- steveklabnik 7y agoThat's correct.