Roc's DEFLATE library comes within 2.6% of C's libdeflate on an M1 Mac

How close can pure functional programming get to C?

Richard Feldman set out to see how close a pure functional language could get to C by optimizing roc-deflate, a DEFLATE package written in Roc, and benchmarking it against libdeflate on the Silesia corpus. Across 144 benchmarks, Roc ran a median 2.6% slower on an M1 MacBook Pro and 8.9% slower on a Ryzen 3900X — with identical output and no streaming support yet. Roc hasn't even hit version 0.1.0.

libdeflate unsurprisingly blows it out of the water (unsurprisingly because this is a very carefully tuned implementation using architecture-specific SIMD, that we can't touch in Lean).
  1. jandrewrogers

    Much of the difference in optimizability is that C/C++ allows you to do fairly extreme copy elision. This is important because memory bandwidth tends to be a major performance bottleneck.

    C/C++ code can trivially reach into some remote bit of state and mutate it directly. The compiler rarely objects, no matter how ugly the access method or pattern. It is up to the programmer to make sure the invariants hold and the compiler can’t always see through it. These elided copies add up, though it usually has a maintainability and safety cost.

    It is related to why functional languages tend to be mediocre for supercomputing in practice despite having nice properties for massive parallelism in theory.

  2. VorpalWay

    > lean-zip beats every single compression level miniz_oxide

    Miniz_oxide is an intentionally simple implementation. It would be more fair to compare it to the newer zlib-rs[1], which even beats zlib-ng (fastest implementation in C)[2].

    [1]: https://lib.rs/crates/zlib-rs

    [2]: https://trifectatech.org/blog/zlib-rs-is-faster-than-c/

  3. WalterBright

    D has a nice feature where a function can be annotated with `pure`, and the compiler will check that the function is pure.

    It's fun trying to reorganize your code to make it pass the `pure` checking.

  4. giovannibonetti

    I wonder if Roc will eventually have high-level abstraction to handle SIMD support. Perhaps by bringing some ideas from Futhark [1], a functional language focused on data parallelism. IIRC, the author has already been interviewed on Richard's podcast.

    [1] https://futhark-lang.org/

  5. gobdovan

    Have you considered exposing these optimisations through a library so programmers can request optimisation passes and have the compiler check the preconditions?

    Asking cuz I'm preparing an article on how fast JS can get and found the same thing, you can get in 10% of optimised C-code with basically any code if you torture V8 enough (excepting SIMD where there seems to be a bug in V8 where it doesn't optimise to SIMD even when beyond obvious). Figured out I could extract it in a lib and do it more streamlined but not sure how well manual transforms generalise.

    Also, when working on the roc-deflate, did you find recurring transformations that could fit that model or were most improvements specific to compression?

  6. andai

    > Roc is not a mature language (it's still weeks away from its first numbered release, 0.1.0)

    It then links to a video where a consultant mentions using in production (for several years already?), which confused me.

    How can you justify using immature technologies for client work? Or is it an extra benefit when it breaks and you have to fix it?

    I'm genuinely curious, maybe it's not as bad as I think. But I've used immature hosting platforms, and that certainly didn't go well for me!

  7. michaelteter

    I never saw Roc before, but at first glance I love it: functional compiled language with good performance and Ruby ergonomics.

  8. uecker

    If you let the agents mess with the code, there seems to be no fundamental reason to use a pure functional language in the first place. The point here is that it is proven correctly. This could be done for C or even assembly. Going to Rust makes no sense either, as this just adds restrictions which are unnecessary if you have a correctness proof.

More from this day

2026-10-24