News for hackers. Stuff that matters.
Re:Rust is now overall faster than C in benchmarks by walki on Sunday January 03, 2021 @04:50PM (#25625581)
OK thanks, indeed Clang is able to generate better assembly using __restrict__. And -O3 generates the same assembly as -O3 -fstrict-aliasing (which is not as good as __restrict__).

I wish there was a C/C++ compiler flag for treating all pointers as __restrict__. However I guess that C/C++ standard libraries wouldn't work with this compiler option (and therefore this compiler option wouldn't be useful in practice).

Re:Rust is now overall faster than C in benchmarks by walki on Monday January 04, 2021 @03:14AM (#25628818)
What's interesting to note though is that I tried marking pointers __restrict__ in the performance critical sections in 2 of my C++ projects and the assembly generated by Clang was identical in all cases!

So while it is true that by default Rust has a theoretical performance advantage (compared to C/C++) because it forbids aliasing pointers I wonder (doubt) whether this will cause Rust binaries to generally run faster than C/C++ binaries.

On the other hand Rust puts security first, so there are lots of array bounds checks in Rust programs (and not all of these bounds checks can be eliminated). Personally I think this feature deteriorates the performance of Rust programs much more than you gain by forbidding aliasing pointers.

Re:Rust is now overall faster than C in benchmarks by Skunkleton on Tuesday January 05, 2021 @03:45PM (#25650769)
> so there are lots of array bounds checks in Rust programs

Depends on how those programs were written. Iterators should avoid bounds checking for example.

Re:Rust is now overall faster than C in benchmarks by dodobirdlord on Sunday January 03, 2021 @07:35PM (#25626726)
Likely most C code, particularly data structure code, would break if compiled with a setting that treats all pointers as restrict.
Re:Rust is now overall faster than C in benchmarks by nzentzis on Sunday January 03, 2021 @07:21PM (#25626639)
I think C and C++ have enough problems with accidental undefined behavior already without making aliased pointers into UB.