Richard Feldman optimized roc-deflate, a compression library in the pure functional language Roc, against C’s libdeflate. His reported median slowdown across 144 benchmarks was 2.6% on an M1 MacBook Pro and 8.9% on a Ryzen 3900X. The comparison covers non-streaming compression on the Silesia corpus, with identical outputs checked.

  • Keep values uniquely owned. Avoiding unnecessary sharing lets Roc reuse storage through in-place mutation while preserving functional semantics.
  • Make safety checks easier to prove. An explicit bounds check before a loop can let the compiler remove repeated checks inside it.
  • Move fixed work to compilation. Compile-time lookup tables can eliminate runtime construction and checks on constant accesses.
  • Choose arithmetic deliberately. Wrapping addition can remove overflow-check overhead when wraparound matches the algorithm’s intended behavior.

The remaining performance gap buys enforced memory safety and a type system that tracks side effects. Pure Roc packages also lack arbitrary foreign-function access and package build scripts, narrowing what a compromised dependency can do.

A single carefully tuned library cannot establish a language-wide performance result. It does show how ownership, data layout, and compiler-visible invariants can matter more than the functional-versus-imperative label.