How close can pure FP get to C?
In Why Lean is Faster Than Rust, an astonishing feat is highlighted: a DEFLATE compression library, written in Lean 4, a functional programming language and proof assistant, outperforms a comparable Rust package with over a billion downloads on crates.io. According to the article, lean-zip matches or surpasses miniz_oxide's compression at higher speeds 15% quicker and with 8.8% smaller output.
However, lean-zip falls short in comparison to libdeflate, the C-based reference implementation, which outperforms it by a significant margin. This disparity is attributed to libdeflate's meticulous optimization, leveraging architecture-specific SIMD instructions that are beyond the reach of Lean.
Enter Roc, a functional programming language with a primary focus on runtime performance. Roc's motto is "Fast, Friendly, Functional," emphasizing speed in both execution and compilation. Despite being in its infancy with only a preliminary release of 0.1.0, Roc's early compiler implementation and language design have paved the way for performance enhancements.
I decided to leverage Roc to challenge libdeflate's supremacy in DEFLATE compression, focusing on non-streaming APIs, using the Silesia corpus for benchmarking and ensuring identical output. The benchmarks, conducted on a 2021 M1 MacBook Pro and an AMD Ryzen 9 3900X Ubuntu machine, reveal that roc-deflate, developed by Niclas Ahden, lags behind libdeflate in performance, being 8.9% slower on average on the Ryzen 3900X and 2.6% slower on the M1 MacBook Pro.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.