I have a recursive call in node.js. I am trying to figure how to optimize it so it uses the lease CPU cycles and has the smallest stack memory.
function baz(callback) {
if (bool){
callback();
return;
}
else{
setImmediate(function(){
return baz(callback);
});
}
}
The only thing I can really tweak is the presence of return statements and where to place them. I think the stack will grow more without returning in the right place.
Is there a profiling tool for node.js where I can see the stack during runtime?