4 ms·
> Idiomatic rust avoids heap allocations, but it very much encourages immutable stack allocation...something that OCaml also tries to encourage. I'm not sure I
by rbehrends 9y ago
> Idiomatic rust avoids heap allocations, but it very much encourages immutable stack allocation...something that OCaml also tries to encourage.
I'm not sure I'm following you here; one of the more common criticisms of OCaml is generally that it (unavoidably) puts too many values on the heap. I mean, even floats get boxed by default, unless the compiler can avoid that.
- CyberDildonics 9y ago> even floats get boxed by default, unless the compiler can avoid that. Yikes, that seems like it would destroy performance.
- rbehrends 9y agoIt's one of OCaml's biggest weaknesses, but it's also not as bad as it sounds. One, records and arrays of floats don't suffer an additional level of indirection. Two, the compiler is actually pretty good at unboxing floats these days. Arguments of non-inlined functions are generally the major reason for boxing to happen (because of ABI requirements). Inner loops should generally be free of unnecessary boxing. Three, even when boxing happens, keep in mind that OCaml uses a very fast bump allocator (which is also inlined). This means that heap allocation of short-lived values is more like alloca() than malloc(). OCaml is still not the language that you'd want to write performance-sensitive numeric code in, but it's generally fine when floating point math is only one aspect of your code or when you're using it as a way to interface with C/Fortran libraries (such as with Owl [1]), sort of like how Python uses NumPy. [1] https://github.com/ryanrhymes/owl https://github.com/ryanrhymes/owl
- deleted 9y ago[deleted]