Maximum number of entries in Node.js Map?

前端 未结 3 1577
时光取名叫无心
时光取名叫无心 2020-12-18 21:04

I was making a large Map in Node.js v11.9.0 and it kept failing with \"FATAL ERROR: invalid table size Allocation failed - JavaScript heap out of memory\". My map\'s keys an

3条回答
  •  没有蜡笔的小新
    2020-12-18 21:38

    What's interesting is if you change your code to create two Map objects and insert into them simultaneously, they both crash at exactly the same point, 16.7:

    var N = Math.pow(2, 26);
    var m1 = new Map();
    var m2 = new Map();
    
    for (var i = 0; i < N; i++) {
      m2.set(i, i + 1);
      m1.set(i, i + 1);
    
      if (i % 1e5 === 0) { console.log(m1.size / 1e6); }
    }
    

    There's something odd happening here when more than 224 entries are made in any given Map, not globally across all Map objects.

    I think you've found a V8 bug that needs to be reported.

提交回复
热议问题