0

Papa Parse appears to be causing Chrome and Opera to crash (Windows 7) if I attempt to parse "large" csv strings of about 1 million rows with about 20 columns. Where the same page successfully loads in Firefox. Chrome and Opera crash even before calling Parse if I have a large csv string defined and include a <script> tag to the papaparse.js library. If I don't include the <script> tag for papaparse.js there are no problems creating large csv strings but then I can't parse them. In my actual use case, I am not generating the large csv strings in javascript but rather pulling them out of a zip archive. Doesn't appear to make any difference if I use the step or chunk functions. You can run the test case here; Test Case Problem code;

<!doctype html>
<html>

<script src="http://papaparse.com/resources/js/papaparse.js"></script>

<body>

<script>

 function my_createMockCSV(rows) {
  var my_csv="a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v\r\n";
  for (var i=1; i<rows; i++) {
   my_csv+= i+","+ i+","+ i+","+ i+","+ i+","+ i+","+ i+","+ i+","+
            i+","+ i+","+ i+","+ i+","+ i+","+ i+","+ i+","+ i+","+
            i+","+ i+","+ i+","+ i+","+ i+","+ i+","+"\r\n";
   }
 return my_csv;
 }


function parseCSV(csv) {

 var rowcount=0;

 Papa.parse(csv, 
               {
               delimiter: ',', 
               worker: false,
               encoding: 'default',
               header: true, 
              chunk: function(results) {
                 rowcount+= results.data.length;
                console.log("Parsed rows: "+rowcount);
               },
             complete: function (results) { 
                 console.log("Complete - parsed: "+rowcount+" rows");
               }
            });

 }

function run_testcase() {
 rows=document.getElementById("rows").value;
 //parseCSV(my_createMockCSV(rows));  
 console.log("Begin Generating CSV ...");
 alert("About to generate Mock CSV");
 var my_csv=my_createMockCSV(rows);
 console.log("End Generating CSV ...");
 alert("About to parse Mock CSV");
 parseCSV(my_csv);
}

</script>

Papaparse test case script: Will crash Chrome, Opera<br/>

Rows: <input id="rows" type="number" value="1000000"> (Try around 1mil rows)
<button onclick="run_testcase();">Run</button>

</body>
</html>
hhtx
  • 1
  • 1

1 Answers1

0

Papa Parse isn't causing the browser to crash.

Chrome and Opera are not efficient with strings like Firefox is. You simply cannot create a string with a million rows and 20 columns in memory like you're doing and expect the browser tab to remain stable.

Comment out the call to Papa.Parse() and you'll see what I mean: the browser still crashes.

Matt
  • 22,721
  • 17
  • 71
  • 112