MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/75nibr/javascripts_promise_is_memory_unsafe/do7kd0r/?context=3
r/javascript • u/alexelcu • Oct 11 '17
77 comments sorted by
View all comments
13
I tried that code in node 7.10.1 and 8.6.0. It didn't crash at all. It just endlessly printed numbers until I killed it.
11 u/alexelcu Oct 11 '17 edited Oct 11 '17 Proof:$ nvm use v7.10.1 $ $ node --version v7.10.1 $ node bench.js ... 2360000 2361000 <--- Last few GCs ---> [21305:0x104000000] 52690 ms: Mark-sweep 1408.5 (1467.0) -> 1408.5 (1436.0) MB, 1840.4 / 0.0 ms (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 1840 ms) last resort [21305:0x104000000] 54684 ms: Mark-sweep 1408.5 (1436.0) -> 1408.5 (1436.0) MB, 1993.3 / 0.0 ms last resort ... FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memoryAlso see a screenshot of Activity Monitor showing the process taking 1.5 GB of RAM.If you try that in Chrome, it will crash faster, as Node.js is less conservative being configured for the server-side, so what happens is that the process first grinds to a halt, with the GC desperately trying to deallocate memory.Cheers, 1 u/cwmma Oct 11 '17 I wonder if it has to do with async stack traces 8 u/alexelcu Oct 11 '17 No, it's simply Promise's implementation.An implementation that works correctly is possible, as can be seen in Funfix's PR, which is a port of the solution implemented by Scala's Future.
11
Proof:
$ nvm use v7.10.1 $ $ node --version v7.10.1 $ node bench.js ... 2360000 2361000 <--- Last few GCs ---> [21305:0x104000000] 52690 ms: Mark-sweep 1408.5 (1467.0) -> 1408.5 (1436.0) MB, 1840.4 / 0.0 ms (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 1840 ms) last resort [21305:0x104000000] 54684 ms: Mark-sweep 1408.5 (1436.0) -> 1408.5 (1436.0) MB, 1993.3 / 0.0 ms last resort ... FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
Also see a screenshot of Activity Monitor showing the process taking 1.5 GB of RAM.
If you try that in Chrome, it will crash faster, as Node.js is less conservative being configured for the server-side, so what happens is that the process first grinds to a halt, with the GC desperately trying to deallocate memory.
Cheers,
1
I wonder if it has to do with async stack traces
8 u/alexelcu Oct 11 '17 No, it's simply Promise's implementation.An implementation that works correctly is possible, as can be seen in Funfix's PR, which is a port of the solution implemented by Scala's Future.
8
No, it's simply Promise's implementation.
Promise
An implementation that works correctly is possible, as can be seen in Funfix's PR, which is a port of the solution implemented by Scala's Future.
Future
13
u/lachlanhunt Oct 11 '17
I tried that code in node 7.10.1 and 8.6.0. It didn't crash at all. It just endlessly printed numbers until I killed it.