HackerPapers

arXiv:1908.05647cs.PL

Counting Immutable Beans: Reference Counting Optimized for Purely Functional Programming

Sebastian Ullrich, Leonardo de Moura

Abstract

Most functional languages rely on some garbage collection for automatic memory management. They usually eschew reference counting in favor of a tracing garbage collector, which has less bookkeeping overhead at runtime. On the other hand, having an exact reference count of each value can enable optimizations, such as destructive updates. We explore these optimization opportunities in the context of an eager, purely functional programming language. We propose a new mechanism for efficiently reclaiming memory used by nonshared values, reducing stress on the global memory allocator. We describe an approach for minimizing the number of reference counts updates using borrowed references and a heuristic for automatically inferring borrow annotations. We implemented all these techniques in a new compiler for an eager and purely functional programming language with support for multi-threading. Our preliminary experimental results demonstrate our approach is competitive and often outperforms state-of-the-art compilers.

arXiv comments
Journal reference
IFL 2019
DOI
Subjects
cs.PLProgramming Languages

On Hacker News

Linked by 7 identifiable commenters in 8 comments across 8 threads, from Dec 2020 to Feb 2025. Found in 1 HN submission from Aug 2019 to Aug 2019. Open submission discussions.

Comments linking this paper, per year.

Discussed in comments8 threads

  1. Neut Programming Language 1 comment
    • There might even be some possibility for cross-pollination with ideas such as Counting Immutable Beans [0]. I’ve long wondered if there could be a functional programming language that made static memory management less verbose and easier to manage without monads and other…

      agentultraView on HNParent context

    • Two main papers about this topic AFAIK are: «Counting Immutable Beans» by Sebastian Ullrich and Leonardo de Moura (https://arxiv.org/pdf/1908.05647.pdf) and «Perceus: Garbage Free Reference Counting with Reuse» by Alex Reinking, Ningning Xie,Leonardo de Moura, Daan Leijen…

      yashrkView on HNParent context

    • Yeah, I believe they said they intend for it to be used as a general purpose programming language. I used it to complete Advent of Code last year. There are some really interesting features for general purpose programming in there. For example: you can code updates to arrays in…

      dunhamView on HNParent context

    • I'm sure the details are different, but the general idea, to me, seems the same as the one descibed by Leo and Sebastian in https://arxiv.org/abs/1908.05647. Both Koka and Lean 4 use reference counting to know if it's safe to reuse a structure. This paper (Daan is a collegue of…

      francassoView on HNParent context

  2. Ask HN: Is Clojure Dead? 1 comment
    • > When I think of how the java streams API is used, it generates lots of garbage (i.e. lots of intermediary allocs) Not extremely relevant because it’s Lean 4 and not Java, but destructive updates can help with that: https://arxiv.org/pdf/1908.05647.pdf Edit: Now linking to the…

      nequoView on HNParent context

    • A paper I quite enjoyed on automatic reference counting for pure, immutable functional programming: https://arxiv.org/abs/1908.05647 It can be quite "fast."

      agentultraView on HNParent context

  3. A simple ray tracer in Lean 4 1 comment
    • I am really enjoying lean 3 as a theorem prover; lean 4 as a programming language is a really intriguing/enticing prospect. The "functional but in place" paradigm is something quite new, as far as I can tell. For reference, see the "Counting Immutable Beans" paper[1] by the…

      tomhouleView on HNParent context

    • The Lean developers put out a paper about v4's reference counting last year which shows that in basic benchmarks, Lean 4 is in the same ballpark as Haskell, Swift, and ML. https://arxiv.org/abs/1908.05647

      lakecresvaView on HNParent context

Submitted to Hacker News

Connected through shared HN threads, not inferred similarity or a recommendation.