Skip to content

Instantly share code, notes, and snippets.

@kenotron
Created October 1, 2017 23:51
Show Gist options
  • Save kenotron/86e33239df43dd62ed15c24d1a440aa9 to your computer and use it in GitHub Desktop.
Save kenotron/86e33239df43dd62ed15c24d1a440aa9 to your computer and use it in GitHub Desktop.
Sets causing tons of GC
const map = new Map();
const set = new Set();
const MAX_KEYS = 10 * 1024 * 1024;
const SET_KEYS = 10 * 1024 * 1024;
console.log("Call map.set() a LOT");
for (let i = 0; i < MAX_KEYS; i++) {
map.set(i, i);
}
for (let i = 0; i < SET_KEYS; i++) {
set.add(Math.floor(Math.random() * SET_KEYS));
}
for (let n of map) {
set.has(n);
}
console.log("DONE");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment