简体   繁体   English

GWT定时器性能

[英]GWT Timer performance

I have this javascript code that I have embedded in my application with JSNI: 我有这个javascript代码,我已经嵌入我的应用程序与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: 但是,我想使用纯GWT代替并尝试此代码:

    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. 当我运行我的应用程序时,GWT计时器非常“滞后”,而且与JSNI函数相比,我几乎无法在UI中输入TextBox。 Is there something wrong with the math function in my code or Timer is just slow? 我的代码中的数学函数有问题还是Timer很慢?

First make sure you're not running your GWT code in development mode, but that you actually build and deploy the application. 首先确保您没有在开发模式下运行GWT代码,但实际上是在构建和部署应用程序。 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. 开发模式可以将您的Java代码实时转换为Javascript,以便进行热部署/实时修改,因此速度非常慢。

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. 还尝试在GWT编译器上使用“漂亮”参数,以便它生成非混淆的Javascript,然后检查GWT如何将Java代码转换为JS,也许那里存在问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM