Maximum size of an Array in Javascript

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 stores ID's of records that have been shown.

Question: How many items can an array hold in Javascript before things start getting slow, or sluggish. I'm not sorting the array, but am using jQuery's inArray function to do a comparison.

The website will be left running, and updating and its unlikely that the browser will be restarted / refreshed that often.

If I should think about clearing some records from the array, what is the best way to remove some records after a limit, like 100 items.

99
задан MayorMonty 4 June 2016 в 04:01
поделиться

1 ответ

Как сказанный @maerics, Ваша целевая машина и браузер определят производительность.

, Но для некоторых чисел реального мира, на моем предприятии 2017 года Chromebook, выполняя операцию:

console.time();
Array(x).fill(0).filter(x => x < 6).length
console.timeEnd();
  • x=5e4 берет 16 мс, достаточно хороший для 60 футов в секунду
  • x=4e6 берет 250 мс, который примечателен, но не грандиозное предприятие
  • x=3e7 берет 1 300 мс, который является довольно плох
  • x=4e7, берет 11 000 мс и выделяет дополнительных 2.5 ГБ памяти

, Таким образом, приблизительно 30 миллионов элементов являются трудным верхним пределом, потому что VM JavaScript падает с утеса в 40 миллионах элементов и вероятно разрушит процесс.

0
ответ дан 24 November 2019 в 05:04
поделиться
Другие вопросы по тегам:

Похожие вопросы: