←back to thread

Zlib-rs is faster than C

(trifectatech.org)
341 points dochtman | 2 comments | | HN request time: 0.039s | source
Show context
johnisgood ◴[] No.43381735[source]
"faster than C" almost always boils down to different designs, implementations, algorithms, etc.

Perhaps it is faster than already-existing implementations, sure, but not "faster than C", and it is odd to make such claims.

replies(10): >>43381810 #>>43381813 #>>43381820 #>>43381959 #>>43382108 #>>43382124 #>>43382267 #>>43385171 #>>43386202 #>>43392542 #
kgeist ◴[] No.43382108[source]
I heard that aliasing in C prevents the compiler from optimizing aggressively. I can believe Rust's compiler can optimize more aggressively if there's no aliasing problem.
replies(1): >>43382303 #
layer8 ◴[] No.43382303[source]
C has the restrict type qualifier to express non-aliasing, hence it shouldn’t be a fundamental impediment.
replies(2): >>43383302 #>>43383607 #
anon-3988 ◴[] No.43383607[source]
> fundamental impediment

This is an interesting word. I wonder why no one has written high performance library code in assembly yet at this point?

replies(2): >>43385867 #>>43388117 #
1. vitus ◴[] No.43388117{3}[source]
> I wonder why no one has written high performance library code in assembly yet at this point?

What do you mean by that?

There is plenty of hand-rolled assembly in low-level libraries, whether you look at OpenBLAS (17%), GMP (36%), BoringSSL (25%), WolfSSL (14%) -- all of these numbers are based on looking at Github's language breakdown (which is measured on a per-file basis, so doesn't count inline asm or heavy use of intrinsics).

There are contexts where you want better performance guarantees than the compiler will give you. If you're dealing with cryptography, you probably want to guard against timing attacks via constant-time code. If you're dealing with math, maybe you really do want to eke out as much performance as possible, autovectorization just isn't doing what you want it to do, and your intrinsic-based code just isn't using all your registers as efficiently as you'd like.

replies(1): >>43477811 #
2. anon-3988 ◴[] No.43477811[source]
And? why isn't everyone writing every softawre in assembly if there's no "fundamental impedement" to doing so.

The answer is that its more ergonomic and easier to reason about. So while you can TECHNICALLY have "algebraic data types" in C i.e. "its just a tagged union so whats the big deal?" I prefer to use them in Rust than C, for whatever unknown reason...

I also don't want to spend my brain cells thinking about pointer provenance and which void* aliases with each other. I would rather spend it on something else, thank you very much.