←back to thread

Zlib-rs is faster than C

(trifectatech.org)
341 points dochtman | 2 comments | | HN request time: 0s | source
Show context
IshKebab ◴[] No.43381686[source]
It's barely faster. I would say it's more accurate to say it's as fast as C, which is still a great achievement.
replies(3): >>43381694 #>>43381776 #>>43381791 #
ajross ◴[] No.43381791[source]
It's... basically written in C. I'm no expert on zlib/deflate or related algorithms, but digging around https://github.com/trifectatechfoundation/zlib-rs/ almost every block with meaningful logic is marked unsafe. There's raw allocation management, raw slicing of arrays, etc... This code looks and smells like C, and very much not like rust. I don't know that this is a direct transcription of the C code, but if you were to try something like that this is sort of what it would look like.

I think there's lots of value in wrapping a raw/unsafe implementation with a rust API, but that's not quite what most people think of when writing code "in rust".

replies(6): >>43381833 #>>43381841 #>>43381849 #>>43382402 #>>43383336 #>>43385335 #
hermanradtke ◴[] No.43381833[source]
> basically written in C

Unsafe Rust still has to conform to many of Rust’s rules. It is meaningfully different than C.

replies(2): >>43381882 #>>43382119 #
est31 ◴[] No.43381882[source]
It has also way less tooling available than C to analyze its safety.
replies(3): >>43382241 #>>43383742 #>>43385568 #
1. wyager ◴[] No.43383742[source]
Miri is better than any C tool I'm aware of for runtime UB detection.
replies(1): >>43384505 #
2. est31 ◴[] No.43384505[source]
Miri is the closest to a UB specification for Rust that there is, coming in the form of a tool so you can run it. It's really cool but Valgrind, which is a C tool that also supports Rust, also supports Rust code that calls to C and that does I/O, both pretty common things for programs to do.