News for hackers. Stuff that matters.
Re:Zlib-rs is faster than C by datadeft on Sunday March 16, 2025 @04:20PM (#43381925)
I thought that the point of Rust is to have safe {} blocks (implicit) as a default and unsafe {} when you need the absolute maximum performance available. You can audit those few lines of unsafe code very easily. With C everything is unsafe and you can just forget to call free() or call it twice and you are done.
Re:Zlib-rs is faster than C by steveklabnik on Sunday March 16, 2025 @04:55PM (#43382225)
> unsafe {} when you need the absolute maximum performance available.

Unsafe code is not inherently faster than safe code, though sometimes, it is. Unsafe is for when you want to do something that is legal, but the compiler cannot understand that it is legal.

Re:Zlib-rs is faster than C by datadeft on Monday March 17, 2025 @09:07AM (#43388181)
True, however I only saw this happens to achieve max perf. I have very limited experience so this is confirmation bias from my end.
Re:Zlib-rs is faster than C by steveklabnik on Monday March 17, 2025 @10:39AM (#43389075)
An example of unsafe not for performance is when interacting with hardware directly.
Re:Zlib-rs is faster than C by ycombinatrix on Monday March 17, 2025 @08:22PM (#43394354)
or the operating system!

opening stdout with file handle 0 is not guaranteed safe by the compiler. there's an "unsafe" somewhere in there.

Re:Zlib-rs is faster than C by WD-42 on Sunday March 16, 2025 @04:56PM (#43382236)
It’s not about performance, it’s about undefined behavior.