The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

ahillman3 (4) [Avatar] Offline
#1
Adam, Robert,

We are getting a inconsistent and very irritating "Slow Script" error while running our GWT(GWT-EXT) application under IE. The application is way too large to post any code, and I have never seen this issue with small examples.

Do you have any suggestions for resolving this?

Are either of you available for a consulting gig?

My boss is quite irate about this issue, which we have been unable to solve, and he wants it fixed ASAP. This is especially urgent as we are supposed to go to production in the next few weeks.

Any assistance that can be provided would be appreciated.

Thanks,
Allen
adam.tacy (269) [Avatar] Offline
#2
Re: Slow Script Error - help needed
Hi Allen,

Bit of a tough one without knowing exactly what your application does.

You get that error if your script is taking too long to run something and the browser wants control (though I guess you knew that from the error!). From a GWT perspective you can get that if you're

a) Trying to parse a large amount of data from the server (e.g. a large XML document), or
b) You're trying to create a large UI

There are probably other cases as well, but the issue will be the same, and there are a couple of techniques that I can think of to help:

1) Cut down (defer) the amount of building you need to do in your construction/initialisation, i.e. if you have 4 chunks of functionality, don't build all 4 at the start, build them only as they are needed - just like the original KitchenSink example from GWT; it only built the panel as the option was selected by the user. This way you cut down on initialisation time, and hopefully remove your "slow script" error.

2) Consider breaking up any construction/parsing using DeferredCommand (or IncrememntalCommand). You can get a bit of an idea from here: http://techzone.enterra-inc.com/?p=25 and this thread: http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/45b8e551f9b2bc58/ . Again, these approached give the browser some control and should get rid of the slow script error.

3) If it is a parsing issue that is taking time, consider if you realy need all that data at that point in time - maybe your are retrieving thousands of lines of data but displaying only 100? In that case, paginate your data retrieval to get just 100 (you can always use GWT to get the next set of data in the background without holding up your display)

4) If you have a lot of text that is really static, consider putting that in the HTML page and then use GWT to pick up and move where needed. For example, in http://gwtfx.adamtacy.com/EffectsExample.html , all the text is static in the HTML and I use a simple GWT method to pick it up and move into the tabs rather than ask the JavaScript to build it all for me (placeHolder is the name of the div in the HTML)

private void replace(final String placeHolder, final String tabName) {
try {
String original = DOM.getInnerHTML(RootPanel.get(placeHolder).getElement());
HTMLPanel newHTML = new HTMLPanel(original);
tp.add(newHTML, tabName);
DOM.setInnerHTML(RootPanel.get(placeHolder).getElement(), "");
} catch (Exception e) {
Window.alert(e.getMessage());
}
}

(I'm not so convinced this will remove the slow script error in normal cases, but if you have an awful lot of static text, then it can't hurt - it also has the benefit of making your application visible to search engines)

Hope some of the above helps!

//Adam
robert.hanson (173) [Avatar] Offline
#3
Re: Slow Script Error - help needed
Just to add to that a little, don't forget that JavaScript is single threaded. That error means that you have some piece of code that it taking too long to complete, and it is tying up that one thread for way too long.

Note that this single thread is used for all code execution and event handling. And if some code is hogging up the thread, then the entire browser will appear to be frozen.

Like Adam mention, break up long running parts of your code using DefferedCommand and IncrementalCommand. They way they work is that they execute the first command, give control back to the browser, then execute the second command, etc...

As long as you release control back to the browser regularly (i.e. share the thread), then you should be ok.
ahillman3 (4) [Avatar] Offline
#4
Re: Slow Script Error - help needed
Thanks to both of you. I'll pursue your suggestions and see what happens. Hopefully we'll find the code that is the cause.

An interesting tidbit. We have a Timer that displays a popup and closes the browser when the user hasn't done anything in the app for 50 minutes. When using IE6 the slow script error shows up in addition to the popup message for the inactivity. What could be causing this when nothing is being done in the application aside from the Timer itself?

Thanks,

Allen

Message was edited by:
ahillman3
adam.tacy (269) [Avatar] Offline
#5
Re: Slow Script Error - help needed
Do you get the slow script when the app starts up, or only after the 50 mins (I have to admit I assumed it was at start up above)?

I can't think why the timer for 50 mins would cause the issue, unless maybe you're creating thousands of them (e.g. creating a new timer after every activity instead of resetting a single timer). But then again, I've never set a time for 50 mins, so maybe there is something subtle going on in the depths given the length of time.

You could rule out any subtle issue by perhaps using a repeating task at greater frequency, for example:

1) After every activity, store the current timestamp in a variable, so you know last activity time
2) Have a repeating task running at relatively short intervals (1 second, 10 seconds, 1 minute - not really sure which, but shorter than 50 minutes) that:
a) gets a new current timestamp and compares to the one stored in (1)
b) if > 50 minutes, then do your closing
c) if < 50 minutes,do nothing and wait for next invocation

The above though is just a shot in the dark assuming that a long timer might have some issue you wouldn't see in a short timer....(or that a short timer might allow IE to do some other stuff that gets blocked in a long timer)

//Adam
ahillman3 (4) [Avatar] Offline
#6
Re: Slow Script Error - help needed
The intermittent slow script errors occur at no particular time randomly throughout the application.

The slow script error with the 50 minute timeout, only occurs on IE6, but appears to be consistent in that browser.

Thanks for the repeating timer idea. I'll try that and see if that particualr slow script error goes away.

Thanks,

Allen
ahillman3 (4) [Avatar] Offline
#7
Re: Slow Script Error - help needed
In case anyone was interested, breaking the timer down into smaller increments did make that particular slow script message go away.
adam.tacy (269) [Avatar] Offline
#8
Re: Slow Script Error - help needed
Allen,

Thanks for the update, always good to hear something's worked! Hope the rest of the project goes smooth.

//Adam