How close can pure functional programming get to C?

275 points · 98 comments on HN · read original →

Points and comments are a snapshot, not live.

Roc's DEFLATE implementation runs within 10% of optimized C library libdeflate.

Richard Feldman benchmarks roc-deflate, a pure functional DEFLATE compression library written in Roc, against libdeflate, a hand-tuned C implementation with architecture-specific SIMD. Across 144 benchmarks on the Silesia corpus, roc-deflate is on average 8.9% slower on a Ryzen 3900X and 2.6% slower on an M1 MacBook Pro. The author notes Roc is pre-0.1.0 and has had minimal package ecosystem optimization, while libdeflate uses SIMD that Roc cannot yet match. Earlier, Lean 4's lean-zip outperformed Rust's miniz_oxide but lost to libdeflate.

What commenters are saying

Commenters discuss the fundamental challenge of matching C's performance from a pure functional language: C's ability to directly mutate memory and control layout is critical for memory-bandwidth-bound tasks. Several note that modern CPUs are inherently place-oriented, favoring spatial and temporal locality that functional abstractions often undermine. One commenter suggests the comparison to libdeflate is slightly unfair because miniz_oxide is intentionally simple, while a newer Rust zlib-rs is faster. Others question using download counts as a performance metric and note that Roc's lack of SIMD support is a key gap.