←back to thread

Zlib-rs is faster than C

(trifectatech.org)
341 points dochtman | 1 comments | | HN request time: 0.252s | source
Show context
kahlonel ◴[] No.43381785[source]
You mean the implementation is faster than the one in C. Because nothing is “faster than C”.
replies(11): >>43381811 #>>43381892 #>>43382209 #>>43382286 #>>43382342 #>>43382418 #>>43382745 #>>43383389 #>>43383690 #>>43384451 #>>43392826 #
nindalf ◴[] No.43382418[source]
Why can’t something be faster than C? If a language is able to convey more information to a backend like LLVM, the backend could use that to produce more optimised code than what it could do for C.

For example, if the language is able to say, for any two pointers, the two pointers will not overlap - that would enable the backend to optimise further. In C this requires an explicit restrict keyword. In Rust, it’s the default.

By the way this isn’t theoretical. Image decoders written in Rust are faster than ones written in C, probably because the backend is able to autovectorise better. (https://www.reddit.com/r/rust/comments/1ha7uyi/memorysafe_pn...).

grep (C) is about 5-10x slower than ripgrep (Rust). That’s why ripgrep is used to execute all searches in VS Code and not grep.

Or a different tack. If you wrote a program that needed to sort data, the Rust version would probably be faster thanks to the standard library sort being the fastest, across languages (https://github.com/rust-lang/rust/pull/124032). Again, faster than C.

Happy to give more examples if you’re interested.

There’s nothing special about C that entitles it to the crown of “nothing faster”. This would have made sense in 2005, not 2025.

replies(1): >>43382557 #
1. burntsushi ◴[] No.43382557[source]
Narrow correction on two points:

First, I would say that "ripgrep is generally faster than GNU grep" is a true statement. But sometimes GNU grep is faster than ripgrep and in many cases, performance is comparable or only a "little" slower than ripgrep.

Secondly, VS Code using ripgrep because of its speed is only one piece of the picture. Licensing was also a major consideration. There is an issue about this where they originally considered ripgrep (and ag if I recall correctly), but I'm on mobile so I don't have the link handy.