←back to thread

Zlib-rs is faster than C

(trifectatech.org)
341 points dochtman | 7 comments | | HN request time: 1.178s | source | bottom
Show context
YZF ◴[] No.43381858[source]
I found out I already know Rust:

        unsafe {
            let x_tmp0 = _mm_clmulepi64_si128(xmm_crc0, crc_fold, 0x10);
            xmm_crc0 = _mm_clmulepi64_si128(xmm_crc0, crc_fold, 0x01);
            xmm_crc1 = _mm_xor_si128(xmm_crc1, x_tmp0);
            xmm_crc1 = _mm_xor_si128(xmm_crc1, xmm_crc0);
Kidding aside, I thought the purpose of Rust was for safety but the keyword unsafe is sprinkled liberally throughout this library. At what point does it really stop mattering if this is C or Rust?

Presumably with inline assembly both languages can emit what is effectively the same machine code. Is the Rust compiler a better optimizing compiler than C compilers?

replies(30): >>43381895 #>>43381907 #>>43381922 #>>43381925 #>>43381928 #>>43381931 #>>43381934 #>>43381952 #>>43381971 #>>43381985 #>>43382004 #>>43382028 #>>43382110 #>>43382166 #>>43382503 #>>43382805 #>>43382836 #>>43383033 #>>43383096 #>>43383480 #>>43384867 #>>43385039 #>>43385521 #>>43385577 #>>43386151 #>>43386256 #>>43386389 #>>43387043 #>>43388529 #>>43392530 #
1. jdefr89 ◴[] No.43381971[source]
Not to mention they link to libc.. All rust code does last I checked…
replies(1): >>43382088 #
2. techjamie ◴[] No.43382088[source]
There is an option to not link to it for instances like OS writing and embedded. Writing everything in pure Rust without libc is entirely possible, even if an effort in losing sanity when you're reimplementing every syscall you need from scratch.

But even then, your code is calling out to kernel functions which are probably written in C or assembly, and therefore "dangerous."

Rust code safety is overhyped frequently, but reducing an attack surface is still an improvement over not doing so.

replies(2): >>43382740 #>>43385885 #
3. jdefr89 ◴[] No.43382740[source]
I agree and binary exploitation/Vulnerability Research is my area of expertise.. The whole "Lets port everything to Rust" is so misguided. Binary exploitation has already gotten 20x harder than say ten years ago.. Even so.. Most big breaches happen because people reuse their password or just give it out... Nation States are pretty much the only parties capable of delivering full kill chains that exploit, say chrome... That is why I moved to the embedded space.. Still so insecure...
replies(2): >>43383936 #>>43386119 #
4. pdimitar ◴[] No.43383936{3}[source]
> The whole "Lets port everything to Rust" is so misguided.

Well, good thing that nobody sane is saying that then.

5. PhilipRoman ◴[] No.43385885[source]
Ironically using C without libc turns out to be easier (except for portability of course). The kernel ABI is much more sane than <stdio.h>. The only useful parts of libc are DNS resolution and text formatting, both of which it does rather poorly.
replies(1): >>43390124 #
6. iknowstuff ◴[] No.43386119{3}[source]
https://github.com/embassy-rs/embassy
7. atiedebee ◴[] No.43390124{3}[source]
By text formatting, do you mean printf and the like? It is pretty powerful in my experience.

Also, DNS resolution isn't part of the C standard, it's a POSIX interface I think.