How close can pure functional programming get to C?
Pursuing C-Level Performance with Pure Functional Programming
Date: October 22, 2026
In a previous analysis titled "Why Lean is Faster Than Rust," the author highlighted a startling achievement: a DEFLATE compression library developed in Lean 4 (a functional language and proof assistant) actually outperformed a Rust-based equivalent. This is particularly notable given that the Rust package in question has surpassed a billion downloads on crates.io.
As noted in the original piece:
lean-zipbeats every single compression levelminiz_oxideprovides, i.e. we're capable of providing the same compression at higher throughput. At its fastest setting we're 15% quicker and the output is 8.8% smaller.
The "Final Boss" of Performance
Despite the victory over Rust, lean-zip encountered a ceiling when facing the industry gold standard for DEFLATE: libdeflate. Written in C, libdeflate remains the undisputed champion.
The reason for this gap is technical: libdeflate utilizes highly tuned, architecture-specific SIMD (Single Instruction, Multiple Data) instructions. Because Lean cannot easily access these low-level hardware optimizations, it simply cannot compete with the raw speed of C in this specific domain.
Enter Roc: A New Challenger
This brings us to Roc, a functional programming language designed specifically for runtime efficiency (though, unlike Lean, it is not a theorem prover).
Roc's guiding philosophy is summarized in its tagline:
"Fast, Friendly, Functional"
The priority is clear: Fast comes first. Both execution speed and compilation time are core design objectives. It is important to note that Roc is still in its infancy:
- It has not yet reached its first numbered release (v0.1.0 is still weeks away).
- The package ecosystem is nascent.
Extensive optimization has been performed on most packages.Almost no optimization work has been done on the ecosystem yet.
Despite this, the author believed that Roc's fundamental language design, its existing optimizations, and its fresh compiler implementation provided a strong enough base to challenge libdeflate.
The Optimization Process
The author focused on roc-deflate, a package created by Niclas Ahden (who utilizes it in professional, paid production environments). The goal wasn't necessarily to obliterate surpass C across every metric, but to see how narrow the gap could be.
The Methodology:
- Focus on non-streaming APIs (streaming is not yet implemented in
roc-deflate). - Utilize the standard Silesia corpus for benchmarking.
- Verify that the output remained bit-identical to the original.
- Perform iterative performance grinding.
# Hypothetical benchmarking command used during the process
./roc-deflate-bench --corpus silesia --level 1 --iterations 15
The Results: Closing the Gap
The benchmarks were conducted on two different architectures to ensure a broad comparison: a 2021 M1 MacBook Pro and an AMD Ryzen 9 3900X running Ubuntu.
Across 144 different benchmarks, roc-deflate was slower than libdeflate on average, but the margin was surprisingly slim. The median performance gap can be expressed as:
- Ryzen 3900X: slower.
- M1 MacBook Pro: slower.
Performance Comparison Table (L1 Compression)
The following table illustrates the throughput (MB/s) for various files within the Silesia corpus at the L1 compression level.
| File | libdeflate (MB/s) | roc-deflate (MB/s) | Note |
|---|---|---|---|
| dickens | 230.57 | 202.92 | Median of 15 runs |
| mozilla | 248.31 | 225.79 | Median of 15 runs |
| mr | 312.26 | 277.57 | Median of 15 runs |
| nci | 601.03 | 529.49 | Fastest file |
| ooffice | 169.98 | 153.99 | Median of 15 runs |
| osdb | 284.01 | 257.14 | Median of 15 runs |
| reymont | 281.14 | 245.80 | Median of 15 runs |
| samba | 344.00 | 309.79 | Median of 15 runs |
| sao | 160.21 | 145.28 | Slowest file |
| webster | 268.58 | 239.18 | Median of 15 runs |
| x-ray | 145.93 | 134.66 | Median of 15 runs |
| xml | 476.83 | 419.07 | Median of 15 runs |
Performance Hierarchy
The following diagram represents the relative performance tiers observed in these DEFLATE implementations:
Final Analysis (L2 Compression)
The trend continued into L2 compression. For example, on the dickens file, libdeflate achieved 161.68 MB/s, while roc-deflate followed closely at 143.60 MB/s. This suggests that a pure functional language, when designed with a "performance-first" mentality, can operate within a very narrow margin of the most optimized C code available.