How much data can javascript contain in a browser?

I created a JSFiddle to find out how much data I can insert into my browser.

Link http://jsfiddle.net/GWxAk/

The code is simple. It just tries to insert as many rows into the array as possible. Lines have an approximate length of 300-310 characters.

My question is: does the result depend on how much memory I have on my PC? Is the browser really different from the browser?

For example, if I have 8 GB of RAM, will I get much more if I have 4 GB?

var s = '';
for (var i = 0; i < 300; i++) {
    s += 'a';
}

array = [];
count = 0;

function doMore() {
    for (var i = 0; i < 1000; i++) {
        count++;
        array.push(s + count);
    }
};

function repeat() {
    doMore();
    document.body.innerHTML = 'size:' + array.length;
    setTimeout(repeat, 100);
}

repeat();

In my case, chrome hangs on 14850000, and I have 4gb RAM. This is an array of almost 15 million items. Not bad, I think.

Do you guys get the same thing? Can someone tell me how to give the browser as much memory as possible.

thank

+5
4

, 16 . , , .

IE crapped out at 16,840,000
Chrome at 14,850,000
Firefox 32,890,000
Safari recycles itself around 8,720,000 (LOL @ Apple)

firefox http://screencast.com/t/3Xl31yGgHWC

+7

Chrome, , 14850000, , 2 , Linux, 700 ,

+2

, UTF8 , 'a' 2 /8 .

  • 14 850 000 * 300 = 4455000000

  • 14850000 * 300 * 2 = 8 910 000 000

  • 8910000000/1024 = 8,701,171.875
  • (8910000000/1024)/1024 = 8,497.238159179688
  • ((8910000000/1024)/1024)/1024 = 8.298084139823914 GB

, , Chromes JS 4 455 000 000 ~ 8.3 .

, , , . 4 , ~ 4298 , java VM .. ..

, s + count not s , . s , , , V8. , - count, - , 9,7438,889 185,85 .

- .

V8 JS:

http://code.google.com/p/v8/issues/detail?id=847

32- - , 64-, ~ 1.9 , , , , .

, :

  • 32bit , js, js VM, , ..
  • , , , .
  • ,

:

+2

On a 32-bit machine, your upper limit will always be 4 GB, not if and / or notes. In practice, it will be a completely different machine for processing (it is not uncommon to open 10 + tabs)

The best way is to store only the data that your user is actively working on, or something that you cannot quickly retrieve from the server. Everything else, get when the user asks for it.

0
source

All Articles