Skip to content Skip to footer
Zlib-rs is faster than C by dochtman

Zlib-rs is faster than C by dochtman

9 Comments

  • Post Author
    IshKebab
    Posted March 16, 2025 at 7:55 pm

    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.

  • Post Author
    johnisgood
    Posted March 16, 2025 at 8:00 pm

    "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.

  • Post Author
    kahlonel
    Posted March 16, 2025 at 8:04 pm

    You mean the implementation is faster than the one in C. Because nothing is “faster than C”.

  • Post Author
    YZF
    Posted March 16, 2025 at 8:12 pm

    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?

  • Post Author
    water9
    Posted March 16, 2025 at 8:15 pm

    [flagged]

  • Post Author
    cb321
    Posted March 16, 2025 at 8:32 pm

    I think this may not be a very high bar. zippy in Nim claims to be about 1.5x to 2.0x faster than zlib: https://github.com/guzba/zippy I think there are also faster zlib's around in C than the standard install one, such as https://github.com/ebiggers/libdeflate (EDIT: also mentioned elsethread https://news.ycombinator.com/item?id=43381768 by mananaysiempre)

    zlib itself seems pretty antiquated/outdated these days, but it does remain popular, even as a basis for newer parallel-friendly formats such as https://www.htslib.org/doc/bgzip.html

  • Post Author
    jrockway
    Posted March 16, 2025 at 8:47 pm

    Chromium is kind of stuck with zlib because it's the algorithm that's in the standards, but if you're making your own protocol, you can do even better than this by picking a better algorithm. Zstandard is faster and compresses better. LZ4 is much faster, but not quite as small.

    Some reading: https://jolynch.github.io/posts/use_fast_data_algorithms/

    (As an aside, at my last job container pushes / pulls were in the development critical path for a lot of workflows. It turns out that sha256 and gzip are responsible for a lot of the time spent during container startup. Fortunately, Zstandard is allowed, and blake3 digests will be allowed soon.)

  • Post Author
    amorio2341
    Posted March 16, 2025 at 8:56 pm

    Not surprised at all, Rust is the future.

  • Post Author
    akagusu
    Posted March 16, 2025 at 10:37 pm

    Bravo. Now Rust has its existence justified.

Leave a comment

In the Shadows of Innovation”

© 2025 HackTech.info. All Rights Reserved.

Sign Up to Our Newsletter

Be the first to know the latest updates

Whoops, you're not connected to Mailchimp. You need to enter a valid Mailchimp API key.