JavaScript 中外部 JSON 对象的最大推荐大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9912642/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 08:11:59  来源:igfitidea点击:

Max recommended size of external JSON object in JavaScript

javascriptjsongetjson

提问by S16

I have a tremendous amount of data to sort and query, and I can't rely on an internet connection. Ideally, I'd like to store my entire data-set as a JSON object (currently around 17MB, but could get much larger) and use something like jLinq or SQLike to query it, as opposed to having to output numerous smaller files.

我有大量数据需要排序和查询,而且我不能依赖互联网连接。理想情况下,我想将我的整个数据集存储为一个 JSON 对象(目前大约 17MB,但可能会变得更大)并使用 jLinq 或 SQLike 之类的东西来查询它,而不是必须输出许多较小的文件。

I'm interested in finding what the largest recommended filesize is for an external getJSON call using JavaScript (jQuery, specifically). 1MB, 20MB, 100MB? Information on the subject is scarce. Information on querying large data-sets client-side is scarce all around.

我有兴趣找到使用 JavaScript(特别是 jQuery)的外部 getJSON 调用的最大推荐文件大小。1MB、20MB、100MB?关于这个主题的信息很少。关于查询大型数据集客户端的信息到处都是稀缺的。

Any information on the subject would be greatly appreciated.

任何有关该主题的信息将不胜感激。

回答by pseudosavant

Your biggest problem will probably be loading time since it will have to convert it from a string of JSON into an actual JavaScript object. The other big problem will be that the entire data set will be in memory for the page. I'm not familiar with any page using 100MB+ of data.

您最大的问题可能是加载时间,因为它必须将其从 JSON 字符串转换为实际的 JavaScript 对象。另一个大问题是整个数据集将在页面的内存中。我不熟悉任何使用 100MB 以上数据的页面。

I made a jsfiddle to test loading performance of large JSON strings. It looks like it takes ~500ms just to parse a ~20MB string of JSON (on a Core i7 machine), and in Chrome it uses 80MB more memory than if the JSON string basically empty. So 100MB could take a few seconds to load and use 400MB+ of memory.

我做了一个jsfiddle 来测试大型 JSON 字符串的加载性能。看起来仅仅解析大约 20MB 的 JSON 字符串就需要大约 500 毫秒(在 Core i7 机器上),而在 Chrome 中,它比 JSON 字符串基本为空时多使用 80MB 的内存。因此 100MB 可能需要几秒钟才能加载并使用 400MB+ 的内存。

This won't solve either of those issues, but have you considered using SQL.js? It is a JavaScript implementation of SQLite. It should make querying that data much easier.

这不会解决这些问题中的任何一个,但是您是否考虑过使用SQL.js?它是 SQLite 的 JavaScript 实现。它应该使查询该数据变得更加容易。