Maximum size of an Array in Javascript

前端 未结 7 1894
我在风中等你
我在风中等你 2020-11-22 10:46

Context: I\'m building a little site that reads an rss feed, and updates/checks the feed in the background. I have one array to store data to display, and another which stor

7条回答
  •  星月不相逢
    2020-11-22 11:04

    Like @maerics said, your target machine and browser will determine performance.

    But for some real world numbers, on my 2017 enterprise Chromebook, running the operation:

    console.time();
    Array(x).fill(0).filter(x => x < 6).length
    console.timeEnd();
    
    • x=5e4 takes 16ms, good enough for 60fps
    • x=4e6 takes 250ms, which is noticeable but not a big deal
    • x=3e7 takes 1300ms, which is pretty bad
    • x=4e7 takes 11000ms and allocates an extra 2.5GB of memory

    So around 30 million elements is a hard upper limit, because the javascript VM falls off a cliff at 40 million elements and will probably crash the process.

提交回复
热议问题