Is optimizing away heap allocations something that Roc currently does?
Are there any docs / plans around this?
In what sense? Like what do you think is on the heap that could be optimized away? Any examples of this in other languages?
We do reuse some allocations instead of making new ones. It's one of the things we do opportunistically if ref count is 1.
Roc does a small-string optimization I believe, I suppose that saves a heap allocation?
Another optimisation we've talked about is removing intermediate lists when you do a chain of operations like map, filter, map. But that's not implemented yet, and no immediate plans.
@Sven van Caem yep, you can learn more here: https://github.com/roc-lang/roc/blob/main/design/language/RocStr.md
I talking about optimizations similar to "fusion" in GHC https://wiki.haskell.org/GHC_optimisations#Fusion
Intermediary lists are a good example.
I believe that's what Brian meant! Either that or deforestation (I forget which is which), which is also planned
njlr has marked this topic as resolved.
Last updated: Jul 06 2025 at 12:14 UTC