Skip to content

Instantly share code, notes, and snippets.

@ox
Last active October 3, 2017 16:36
Show Gist options
  • Save ox/0292eeffd575add5fd117f44601221bf to your computer and use it in GitHub Desktop.
Save ox/0292eeffd575add5fd117f44601221bf to your computer and use it in GitHub Desktop.
Test Promise memory usage during recursive promises
const Promise = require('bluebird');
const memwatch = require('memwatch-next');
function async() {
return Promise.resolve();
}
function run(iter=0) {
if (iter >= 10000000) { return Promise.resolve(); }
return async()
.then(() => run(iter + 1));
}
const hd = new memwatch.HeapDiff();
run()
.catch((err) => {console.error(err)})
.finally(() => {
const diff = hd.end();
console.log(diff);
});
$ NODE_ENV=production node promise-test.js
{ before: { nodes: 33277, size_bytes: 4948264, size: '4.72 mb' },
after: { nodes: 31863, size_bytes: 4683560, size: '4.47 mb' },
change:
{ size_bytes: -264704,
size: '-258.5 kb',
freed_nodes: 2740,
allocated_nodes: 1326,
details:
[ [Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object] ] } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment