Live data from Hacker News

Debunking that C++ is faster and safer than Rust

viva64.com

1–10 of 84 posts

Re: Debunking that C++ is faster and safer than Rust

#3
This is an endlessly perplexing headline, as its core assertion, "C++ is faster and safer than Rust", is what the body of the article spends its whole time attempting to refute. A more accurate title for the content of this article would be "Debunking the myths that Rust is not safer or as fast as C++".

Re: Debunking that C++ is faster and safer than Rust

#4
This article is a bit click-baity. It's more about busting myths by a particular C++ programmer against rust.

Anyway for a truth (well maybe it is a myth?) that we can't bust yet... Rust is simply not available on all platforms that C++ is. Two platforms that I think are missing:

* 16-bit MS-DOS

* 32-bit PowerPC (Linux)

Re: Debunking that C++ is faster and safer than Rust

#6
Important to note that PVS-Studio is a static analysis tool for C++. As such it would definitely be in their interest to have more people use C++, but since they're arguing in favor of Rust here it definitely speaks to the fact that their analysis is unbiased.

Re: Debunking that C++ is faster and safer than Rust

#7
> The bug has been present in LLVM since 2006. It's an important issue as you want to be able to mark infinite loops or recursions in such a way as to prevent LLVM from optimizing it down to nothing. Fortunately, things are improving. LLVM 6 was released with the intrinsic llvm.sideeffect added, and in 2019, rustc got the -Z insert-sideeffect flag, which adds llvm.sideeffect to infinite loops and recursions. Now infinite recursion is recognized as such (link:godbolt). Hopefully, this flag will soon be added as default to stable rustc too.

Be aware that this isn't a LLVM bug but a direct consequence of the insanity of C++ specification (wrt. forward progress induced undefined behaviour).

The C++ rules around forward progress allow C++ compilers to faster eliminate code which doesn't produce any observable side effects (without the code triggering undefined behaviour) but it also removes code which intentionally or not hangs the process in a busy loop or is intended to cause a stack overflow... (e.g. for testing protections).

The flag currently isn't added to rust as the penalty effect on compiler time (needs to run more analysis) and runtime (doesn't eliminate all code it should) is currently pretty high.

So this might take a while until _fully_ fixed (you always can pass in the flag yourself if you want).

Through some fixes which make it harder to hit the bug until a proper solution is found _might_ not be so far of (I hope).

Re: Debunking that C++ is faster and safer than Rust

#8
post #7

> The bug has been present in LLVM since 2006. It's an important issue as you want to be able to mark infinite loops or recursions in such a way as to prevent LLVM from optimizing it down to nothing. Fortunately, things are improving. LLVM 6 was released with the intrinsic llvm.sideeffect added, and in 2019, rustc got the -Z insert-sideeffect flag, which adds llvm.sideeffect to infinite loops and recursions. Now infi…

We're currently talking about this in Rust-land: https://blog.rust-lang.org/inside-rust/2020/03/19/terminatin... (comment thread: https://internals.rust-lang.org/t/resolving-rusts-forward-pr...)

Re: Debunking that C++ is faster and safer than Rust

#9
post #7

> The bug has been present in LLVM since 2006. It's an important issue as you want to be able to mark infinite loops or recursions in such a way as to prevent LLVM from optimizing it down to nothing. Fortunately, things are improving. LLVM 6 was released with the intrinsic llvm.sideeffect added, and in 2019, rustc got the -Z insert-sideeffect flag, which adds llvm.sideeffect to infinite loops and recursions. Now infi…

It's indeed not a bug for C++, but to be clear it is a bug for C and Rust that use LLVM but don't have that same guarantee as C++. LLVM assumes that guarantee holds for all frontends, and added the sideeffect opcode so that frontends for languages that don't have that guarantee have a way out.

Re: Debunking that C++ is faster and safer than Rust

#10
post #6

Important to note that PVS-Studio is a static analysis tool for C++. As such it would definitely be in their interest to have more people use C++, but since they're arguing in favor of Rust here it definitely speaks to the fact that their analysis is unbiased.

They have also previously posted some negative ones too, so I was surprised to read this for that reason. I think it also contributed to my confusion around the title vs text, that others have expressed in this thread.
Post reply on HN