Memory management

Hi!

In my programs I often find myself putting a few values in an array, and while I don’t know how many of them I’ll need, I do know that variable is capped. For instance, I might declare an array of 100 elements max, that won’t grow anytime. I’ll be mutating those elements often though. For the sake of simplicity lets say all the elements in the array are unboxed types or records of unboxed types.

In that scenario, having the array in the stack would be very beneficial, but, as per my understanding, the best I can aim for is cache locality using Vector and such (which honestly should be more than enough). Nevertheless, my questions are:

  1. Is my understanding correct? and if so, more importantly,
  2. Is this something dependent types would enable?
  1. Are you looking for something like vector-sized: Size tagged vectors? While in theory it could have been more efficient, currently it is built upon vector, so does not offer any performance bonuses.
1 Like

Wait a minute!!! Ha, so I guess my intuition failed me. I thought currently any type tagging would only be used by the type checker to enhance safety, and that’s what I also read from the package readme.

But then, following the Vulkan PR linked in it, the author claims significant improvements both on compilation time and runtime (I assume that’s what he means by compiler allocations).

So then, ghc is able to use those type tags to optimize the code? How?? I could try guessing, but my intuition deserves no credit in the subject :stuck_out_tongue: - Or is it just an improvement over their previous implementation?

From what I understand, the “stack” of a Haskell program is in fact a section of the heap. If you’re looking for a real C stack, that’s something you’d get by using the FFI.

1 Like