Hey @asterite, after studying your code, I just replaced the Arrays with Slices in the two methods twins_sieve and nextp_init in my original version, as you did in your code, and here are the results, for input of 1_000_000_000_000.
My original using Arrays: 174.5 secs
My original using Slices: 161.1 secs
The memory still grows as before, but that’s seem to be due to, as your stated, the incomplete multi-threading model.
I want to say I really appreciate how you jumped on this issue and made the code much better. I have no doubt Crystal will catch up to Nim, Rust, et al, in multi-processing very soon.
Please feel free to use this application as you please as a test case.
Here is the updated gist of my code using Slices.
Yes, to be absolutely clear, doing so is inherently unsafe and can easily lead to memory leaks! LibC.malloc returns a raw Pointer, which you can then wrap in a slice and pass around like any other, but doing so discards guarantees the compiler offers (memory safety).
I am planning to do it but don’t have enough time. It may be equal or even may be more work than debugger support (I spent 6 months on it).
But I am still willing to work on it as it is an interesting idea to implement.