[Ur] Memory allocation for purely functional code
Adam Chlipala
adamc at csail.mit.edu
Sun Mar 29 08:00:40 EDT 2015
On 03/29/2015 04:52 AM, Sergey Mironov wrote:
> What memory allocation mechanism does Ur/Web use for making
> nested purely-functional calls?
It's all region-based memory allocation, a scheme not really designed
for intensive computation with many intermediate results.
> What can I do to reduce the memory consumption?
Structure your code so that many intermediate computations have types
like [int], so that the compiler sees that intermediate values can be
freed safely afterward. The same optimization applies hierarchically
for trees of nested computations, where many [int]s are computed using
many intermediate [int]s, etc.
The general rule is that intermediate values are freed after
computations of types built out of [int], [float], etc. using further
layers of record types.
More information about the Ur
mailing list