Stream: beginners

Topic: ✔ Are heap allocations ever optimized away?


view this post on Zulip njlr (Jan 13 2024 at 13:30):

Is optimizing away heap allocations something that Roc currently does?

Are there any docs / plans around this?

view this post on Zulip Brendan Hansknecht (Jan 13 2024 at 16:59):

In what sense? Like what do you think is on the heap that could be optimized away? Any examples of this in other languages?

view this post on Zulip Brian Carroll (Jan 13 2024 at 18:40):

We do reuse some allocations instead of making new ones. It's one of the things we do opportunistically if ref count is 1.

view this post on Zulip Sven van Caem (Jan 13 2024 at 18:41):

Roc does a small-string optimization I believe, I suppose that saves a heap allocation?

view this post on Zulip Brian Carroll (Jan 13 2024 at 18:42):

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.

view this post on Zulip Kiryl Dziamura (Jan 13 2024 at 18:58):

@Sven van Caem yep, you can learn more here: https://github.com/roc-lang/roc/blob/main/design/language/RocStr.md

view this post on Zulip njlr (Jan 13 2024 at 22:02):

I talking about optimizations similar to "fusion" in GHC https://wiki.haskell.org/GHC_optimisations#Fusion

Intermediary lists are a good example.

view this post on Zulip Sven van Caem (Jan 13 2024 at 22:10):

I believe that's what Brian meant! Either that or deforestation (I forget which is which), which is also planned

view this post on Zulip Notification Bot (Jan 13 2024 at 22:22):

njlr has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC