C++

Roc’s roc-deflate Gets Within Single-Digit Median Gap of C’s libdeflate

A Roc DEFLATE package came within single digits of the C library libdeflate on median benchmarks, while keeping memory safety and purity guarantees.

Following a report that a Lean 4 DEFLATE library beat Rust's miniz_oxide, the author turned to Roc, a functional language focused on runtime speed, to test it against libdeflate, a heavily tuned C implementation that uses architecture-specific SIMD. The work centered on roc-deflate, a package written by Niclas Ahden, and focused on its non-streaming APIs, with outputs checked for identity against the Silesia corpus.

Across 144 benchmarks, roc-deflate was slower on average than libdeflate. The median gap was 8.9% on an AMD Ryzen 9 3900X and 2.6% on an M1 MacBook Pro. On the worst inputs it trailed by 18%, while on the best inputs it was slightly over 18% faster, reflecting differences between the two implementations rather than any special Roc advantage.

The author argues that Roc's guarantees are the trade-off: memory safety, automatic reference counting, bounds checks, no unsafe escape hatch, enforced purity tracked in function types, and no arbitrary FFI or build scripts in packages. Roc-specific techniques that helped included avoiding unnecessary sharing, hoisting bounds checks, compile-time lookup tables, and wrapping arithmetic. Roc 0.1.0, the first numbered release, is still upcoming.

Source: rtfeldman.com


Posted

in

by

Tags: