Creating large JS array causes program to stop with no errors

I was coding in javascript on begain with a naive prime number sieve like I would in C++, but something strange happened when I tried to create the array. This code:

const prime = Array(1e9).fill(true);

produced the output:

Console output

Standard Output Stream:

> before


Found: Nothing

Expected: 6

There was no javascript exception message, no timeout message, and no native process error message.

After some println debugging to narrow down the error and experimenting with array creation, I found that creating an array of a billion elements probably causes the javascript VM to run out of memory and so the process is killed?

It seems like an issue with CodinGame that some error isn’t reported in the IDE. Would it be possible to ensure an error message is printed? Even “process exited with exit code 1” would be better than seeing nothing.

1 Like

We could probably but that would be hard to implement on our side. JS does not go out of memory, it is killed by the jail (oom killer of the memory cgroup) because it goes beyond the allocated memory for the jailed process.
We already have a feature filed for this but don’t expect a quick resolution.

Personal note: A “billion” elements, really? for a CodinGame puzzle?

I can confirm a similar problem for C++. Segfaults are not sent to the console.

That’s reasonable, thanks. Is there some different bug tracker I could have searched before posting? (I didn’t want to create a duplicate, but nothing on this forum seemed similar).

Aha, I miscounted–the problem only requires checking up to 8-digits numbers, so that’s 10x too much. But looking at the CodinGame limits I think with a proper bitset a billion bits would fit.

Well, to be true, you shouldn’t complain about limits but about a wrong approach to a solution.
An array of 1 billion items?, That’s insane for a problem of this kind.