Solved

how to avoid "Error: script stack space quota is exhausted" when loading a big table with a javascript

Posted on 2009-04-04
10
3,293 Views
Last Modified: 2013-12-07
I'm trying to run the following script using google's API. The script works perfectly, but as soon as I add too many rows (with the "data.setValue" command)  it does not work anymore in Firefox or IE. The final script should be able to load around 95,000 rows. I've read it has to do with the script stack space. With Opera I'm actually able to load the page (but it runs very slowly).

Is there a way to improve the loading of the data? thanks!!!!!!!!!!!!!!!!!
<html>

  <head>   
 

 <script type="text/javascript" src="http://www.google.com/jsapi"></script>

    <script type="text/javascript">

      google.load('visualization', '1', {'packages':['motionchart']});

      google.setOnLoadCallback(drawChart);

      function drawChart() {

        var data = new google.visualization.DataTable();

        data.addRows(95000);

        data.addColumn('string', 'ID');

        data.addColumn('number', 'year');

        data.addColumn('number', 'Sum1');

        data.addColumn('number', 'Sum2');

        data.addColumn('number', 'Sum3');
 

data.setValue(0, 0, 'a_1'); data.setValue(0, 1, 2000); data.setValue(0, 2, 0); data.setValue(0, 3, 5); data.setValue(0, 4, 400);

data.setValue(1, 0, 'a_1'); data.setValue(1, 1, 2001); data.setValue(1, 2, 1); data.setValue(1, 3, 11); data.setValue(1, 4, 880);

data.setValue(2, 0, 'a_1'); data.setValue(2, 1, 2002); data.setValue(2, 2, 2); data.setValue(2, 3, 16); data.setValue(2, 4, 1550);

data.setValue(3, 0, 'a_1'); data.setValue(3, 1, 2003); data.setValue(3, 2, 3); data.setValue(3, 3, 19); data.setValue(3, 4, 1690);

data.setValue(4, 0, 'a_1'); data.setValue(4, 1, 2004); data.setValue(4, 2, 4); data.setValue(4, 3, 23); data.setValue(4, 4, 1770);

data.setValue(5, 0, 'a_1'); data.setValue(5, 1, 2005); data.setValue(5, 2, 5); data.setValue(5, 3, 29); data.setValue(5, 4, 2400);

data.setValue(6, 0, 'a_1'); data.setValue(6, 1, 2006); data.setValue(6, 2, 6); data.setValue(6, 3, 32); data.setValue(6, 4, 2460);

data.setValue(7, 0, 'a_1'); data.setValue(7, 1, 2007); data.setValue(7, 2, 7); data.setValue(7, 3, 35); data.setValue(7, 4, 2520);

data.setValue(8, 0, 'a_1'); data.setValue(8, 1, 2008); data.setValue(8, 2, 8); data.setValue(8, 3, 41); data.setValue(8, 4, 2890);

data.setValue(9, 0, 'a_1'); data.setValue(9, 1, 2009); data.setValue(9, 2, 9); data.setValue(9, 3, 43); data.setValue(9, 4, 3170);
 
 

*************** ROWS REMOVED FROM ORIGINAL CODE *******************************
 
 

var chart = new google.visualization.MotionChart(document.getElementById('chart_div'));

        chart.draw(data, {'width': 1600, 'height': 700});

      }

    </script>
 

 </head>
 

  <body>

 <div id="chart_div"  style="width: 800px; height: 400px;"></div>

  </body>

</html>

Open in new window

0
Comment
Question by:catalini
  • 5
  • 3
  • 2
10 Comments
 
LVL 49

Expert Comment

by:Roonaan
Comment Utility
Hi,

Might be a silly question, but what are you trying to do that required 95k rows loaded through javascript?
From an end user perspective this cannot be anything other than unusable I would expect.
When you are doing some sort of calculation, you'd rather do them cached and serverside for both your server as your end users sake.

k/r

Arnoud
0
 

Author Comment

by:catalini
Comment Utility
this is not developed for an end-user. I'd like to see the visualize the results for myself using google APIs. It's not a problem if it takes too long to load.
0
 
LVL 49

Expert Comment

by:Roonaan
Comment Utility
What kind of calculations and visualization? Do you need to have all your rows in memory, or can you do partial calculations, to save on memory usage?
0
 

Author Comment

by:catalini
Comment Utility
it's using all the rows for a motion chart (see http://code.google.com/apis/visualization/documentation/gallery/motionchart.html)...

is there a way to expand the browser's script stack? I've got plenty of memory available (3GB!).

I've seen someone using an iframe trick, but I'm not sure how to implement it. Is there a better way to input the data than mine? Maybe from a csv file?

thanks!!!
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 500 total points
Comment Utility
The api mentions that you can use CSV or JSON as a data source. I don't see them mentioning anything on the amount of data though

http://code.google.com/intl/nl/apis/visualization/documentation/dev/implementing_data_source.html
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:catalini
Comment Utility
I wasn't able to load it using their csv example. I'm running the script locally on a html page of about 12MB...
0
 

Expert Comment

by:ProjectRAIN
Comment Utility
Hi,

I'm actually having the same problem.
But as for my scenario, I like to grab a template file remotely using
jquery ajax, the also grab the data also using jquery - ajax in json format.
then bind them both template and data for display.
In theory this binding seems faster, there's just a "but"

the problem occurs when I try to retrieved bunch of records.

according to JQuery devs. they won't fix this or find another way for it.
http://dev.jquery.com/ticket/3250

but i've tried using the "complete" callback instead but still having the same
problem because i still need to convert it to string for the template binding.

Hope there's really a solution out there!

Thanks!
0
 

Author Comment

by:catalini
Comment Utility
using Opera instead of Firefox or IE solved the problem.
0
 

Author Comment

by:catalini
Comment Utility
no solution was posted.
0
 

Expert Comment

by:ProjectRAIN
Comment Utility
this is due to data byte size downloaded from the server to the client side(browser) which the browser(FF) has smaller limit to carry the data in the Javascript.

to reproduce this error, you grab a large size of data and assign it to your javascript variable.
sorry, i forgot the limit set by FF.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Several part series to implement Internet Explorer 11 Enterprise Mode
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now