Translate Ruby: arry.product -> Crystal

I was using 0.35.1, and I was still getting the GC warnings. I’m not sure how to turn the warnings off, but I’m pretty happy with it warning me when it tries to allocate a continuous block of memory 800 MB long.

Yeh, I just wanted to see how much impact it had on speed to output those messages.

My system has enough mem to accommodate all the recursions, so wondering also how to tell compiler to use whatever mem it needs to use at runtime.

How big are those arrays?

Right now the way arrays expand is, if they run out of capacity the capacity is doubled. Maybe it should’t be like that. For example in Java it’s apparently newCapacity = oldCapacity + (oldCapacity >> 1).

You can try this by reopening Array and redefining double_capacity:

class Array
  private def double_capacity
    # Try something else here
    resize_to_capacity(@capacity == 0 ? 3 : (@capacity * 2))
  end
end

There are 2 cases where the messages consistently occur, for the last output example.
htop shows that’s when the max memory usage occurs, then it drops back down, which is interesting that for those digits they would generate the most data while not being the largest values.

I’m just trying to understand what’s going on, because the Ruby versions use up to 50% of mem but never produce GC warnings, and are presumably creating the same size arrays.

[1787878888787871]
[2787878888787872]
GC Warning: Repeated allocation of very large block (appr. size 402657280):
        May lead to memory leak and poor performance
[308787855558787803]
[48333332623333384]
[5787878998787875]
GC Warning: Repeated allocation of very large block (appr. size 805310464):
        May lead to memory leak and poor performance
[608787855558787806]
[748867523325768847]
[808696968869696808]
[968787783387787869]
####

Ruby doesn’t use a GC that emits warnings. And these are just warnings. We should disable them because they are useless. So for now you can just ignore these warnings.