Last active
October 3, 2017 16:36
-
-
Save ox/0292eeffd575add5fd117f44601221bf to your computer and use it in GitHub Desktop.
Test Promise memory usage during recursive promises
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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