How close can pure functional programming get to C?(rtfeldman.com)
275 points by stmonty 1 day ago | 99 comments
tl;dr: Roc, a pure functional language with automatic memory management and mandatory bounds checking, achieved DEFLATE compression performance within a median 2.6-8.9% of libdeflate (a heavily SIMD-optimized C library) on the Silesia corpus, even beating it on some inputs. The author argues the small performance gap is worth it for guarantees like memory safety, pure functions, deterministic cross-target behavior, and supply-chain security (no FFI or build scripts). Key optimizations leveraged Roc-specific features like opportunistic in-place mutation, compile-time lookup tables, hoisted bounds checks, and wrapping arithmetic.
HN Discussion:
  • ↓C/C++ allows aggressive copy elision and direct memory mutation that functional languages inherently can't match
  • ↓The benchmark comparison is unfair; should compare against modern optimized implementations like zlib-rs
  • ↑Roc looks appealing as a functional language with good performance and ergonomics
  • ↓The benchmark lacks crucial data on compression ratios at each level, making conclusions questionable
  • •Curiosity about future directions like SIMD abstractions or exposing optimization passes as libraries