简体   繁体   English

在html5 localStorage中存储十亿个double / int数组?

[英]Storing Array of a billion double's / ints in html5 localStorage?

I'm pushing the limits of HTML5 here. 我在这里推动HTML5的极限。

I have this problem: I have an javascript array of a billion doubles (or ints), anyways A LOT of numbers. 我有这个问题:我有一个javascript数组,其中包含十亿个double(或整数),无论如何都是很多数字。 I want to store this in the HTML5 localStorage. 我想将其存储在HTML5 localStorage中。

You may say, hey, just use JSON.Stringify, BUT, JSON.Stringify produces a huge 200MB string. 您可能会说,嘿,只需使用JSON.Stringify,BUT,JSON.Stringify就会产生200MB的巨大字符串。 Because, a number (0.03910319 for example), is stored as a string (so each number is taking up some bytes instead of just a few bytes for the whole number). 因为一个数字(例如0.03910319)存储为字符串(所以每个数字占用一些字节,而不是整个整数的几个字节)。

I was thinking about base64 encoding the numbers in the array first, and then applying JSON.stringify? 我在考虑先对数组中的数字进行base64编码,然后再应用JSON.stringify?

Or is it for example better to JSON.Stringify and then GZip or use some compression function? 还是最好先使用JSON.Stringify然后使用GZip或使用某些压缩功能?

Come up with your creative ideas to encode/decode an javascript array of A BILLION ints/doubles in an efficient matter to a localStorage variable. 提出您的创意,以高效的方式将A BILLION int / double的javascript数组编码/解码为localStorage变量。

TensorFlowJS TensorFlowJS

I looked at TensorflowJS, my array is basically a 1-D Tensor. 我看了TensorflowJS,我的数组基本上是一维Tensor。 Tensorflow has some storage capabilities for models... Maybe that is a feasible solution. Tensorflow具有模型的某些存储功能...也许这是一个可行的解决方案。

For anyone who is also dealing with this problem: 对于也正在处理此问题的任何人:

I used a Float32Array (javascript typed array) for my data. 我为数据使用了Float32Array(JavaScript类型的数组)。

A Float32Array is easily stored in IndexedDB using https://github.com/localForage/localForage 使用https://github.com/localForage/localForage可轻松将Float32Array存储在IndexedDB中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM