I have this javascript code that I have embedded in my application with JSNI:
var i=0;
setInterval(function(){
data.push(Math.cos(i++/25) - 0.2 + Math.random()*0.3);
waveform.update({
data: data
});
}, 50);
However, I want to use pure GWT instead and tried this code:
new Timer() {
private long i = 0;
public void run() {
long value = (long) ((Math.cos(i++/25) - 0.2 + Math.random() * 0.3));
updateData(value); // just a wrapper for the javascript function above
}
}.scheduleRepeating(50);
When I run my application, with the GWT timer its quite “laggy” and that I almost can’t type in the TextBox in the UI, compared to the JSNI function. Is there something wrong with the math function in my code or Timer is just slow?
First make sure you’re not running your GWT code in development mode, but that you actually build and deploy the application. Dev mode makes some sort of on-the-fly converstion of your Java code to Javascript in order to allow hot-deploy/real-time modifications and because of this is very slow.
Also try using the “pretty” argument on the GWT compiler so that it generated non obfuscated Javascript and then check out how your Java code gets translated to JS by GWT, maybe there’s an issue there.