macintosh.world | Log In | Register

Today | News | Books | Recipes
Notes | QuickTake | Wiki | Browse
Maps | Reference | Reddit | YouTube
Chat | Games | About

How close can pure FP get to C?

Open Original Page

How close can pure FP get to C?




How close can pure FP get to C?

In Why Lean is Faster Than Rust, the author shares an impressive result: a DEFLATE compression library written in Lean 4, a functional programming language and proof assistant, outperforming an equivalent Rust package that crates.io says has been downloaded over a billion times. From the article:

lean-zip beats every single compression level miniz_oxide provides, 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.

However, the article also notes that while they managed to surpass Rust's miniz_oxide, they were no match for the end boss of DEFLATE performance: libdeflate, written in C.

lean-zip is certainly not the best here: 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).

Enter Roc, a functional programming language (but not a theorem prover) with an explicit focus on runtime performance.

Roc's tagline is "Fast, Friendly, Functional," and Fast comes first because both running fast and compiling fast have always been central goals. Roc is not a mature language (it's still weeks away from its first numbered release, 0.1.0), and its nascent package ecosystem has had almost no optimization work done on it. Still, between its language design, longstanding optimizations, and brand-new compiler implementation, I figured Roc already had enough of a foundation in place to take on the champ: libdeflate.

So I spent a bunch of time grinding through performance optimizations on roc-deflate, a package Niclas Ahden wrote (and uses in paid production work) for DEFLATE compression. I didn't expect to beat libdeflate's performance across the board, but I wanted to see how close it could get on the non-streaming APIs (as roc-deflate hasn't implemented streaming yet), using the classic Silesia corpus for benchmarking and verifying that it produced identical outputs.

Here's where the benchmarks stand today, running on the 2021 M1 MacBook Pro where I did all the optimization work, as well as on an AMD Ryzen 9 3900X Ubuntu machine for an x64 comparison.

roc-deflate ran these 144 benchmarks slower on average than libdeflate, in the median case 8.9% slower on the Ryzen 3900X, and 2.6% on the M1 MacBook Pro.


Compression on Silesia corpus





M1 MacBook Pro
Ryzen 3900X Ubuntu



700
600
500
400
300
200
100
0

file that ran fastest

file that ran slowest


libdeflate
roc-deflate


libdeflate at L1 compression
230.57 MB/s compressing dickens

(median across 15 runs)


libdeflate at L1 compression
248.31 MB/s compressing mozilla

(median across 15 runs)


libdeflate at L1 compression
312.26 MB/s compressing mr

(median across 15 runs)


libdeflate at L1 compression
601.03 MB/s compressing nci

(median across 15 runs)


libdeflate at L1 compression
169.98 MB/s compressing ooffice

(median across 15 runs)


libdeflate at L1 compression
284.01 MB/s compressing osdb

(median across 15 runs)


libdeflate at L1 compression
281.14 MB/s compressing reymont

(median across 15 runs)


libdeflate at L1 compression
344.00 MB/s compressing samba

(median across 15 runs)


libdeflate at L1 compression
160.21 MB/s compressing sao

(median across 15 runs)


libdeflate at L1 compression
268.58 MB/s compressing webster

(median across 15 runs)


libdeflate at L1 compression
145.93 MB/s compressing x-ray

(median across 15 runs)


libdeflate at L1 compression
476.83 MB/s compressing xml

(median across 15 runs)


roc-deflate at L1 compression
202.92 MB/s compressing dickens

(median across 15 runs)


roc-deflate at L1 compression
225.79 MB/s compressing mozilla

(median across 15 runs)


roc-deflate at L1 compression
277.57 MB/s compressing mr

(median across 15 runs)


roc-deflate at L1 compression
529.49 MB/s compressing nci

(median across 15 runs)


roc-deflate at L1 compression
153.99 MB/s compressing ooffice

(median across 15 runs)


roc-deflate at L1 compression
257.14 MB/s compressing osdb

(median across 15 runs)


roc-deflate at L1 compression
245.80 MB/s compressing reymont

(median across 15 runs)


roc-deflate at L1 compression
309.79 MB/s compressing samba

(median across 15 runs)


roc-deflate at L1 compression
145.28 MB/s compressing sao

(median across 15 runs)


roc-deflate at L1 compression
239.18 MB/s compressing webster

Links

Open - Why Lean is Faster Than Rust
Open - DEFLATE compression
Open - Lean 4
Open - crates.io says
Open - libdeflate
Open - Roc
Open - Fast comes first
Open - longstanding optimizations
Open - brand-new compiler implementation
Open - roc-deflate

Browse another page:

URL