3 ms·
If I try to ask for a large number (say 1 million) I run out of RAM: $ node app.js FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory
by bascule 15y ago
If I try to ask for a large number (say 1 million) I run out of RAM:
$ node app.js
FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory
Somehow you're using O(n) RAM to do the calculation. Seems bad bro.
This code is the epitome of roflscale
- Wilfred 15y agoThat's a consequence of memoisation. It scales better than the original code though. Still, the original point (node is cooperatively multitasked) was clear. Anything beyond that and I just want to reach for better Fibonacci algorithms.
- logancapaldo 15y agoAnd this is why, any cache without an eviction policy and/or size limitation is bad (and memoization _is_ a cache). I shudder every time I see a "magical" memoization function whose interface is just memo function-to-memoize
- rubyinghana 15y agoIf you had brain, you would know that JavaScript only has 52 bits of integer precision. Anything bigger than Fib(~83) is not accurate number and waste of time in JS.