Java 如何加速 gwt 编译器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1011863/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:15:58  来源:igfitidea点击:

How do I speed up the gwt compiler?

javaperformancegwt

提问by skaffman

We're starting to make heavier use of GWT in our projects, and the performance of the GWT compiler is becoming increasingly annoying.

我们开始在我们的项目中更多地使用 GWT,并且 GWT 编译器的性能变得越来越令人讨厌。

We're going to start altering our working practices to mitigate the problem, including a greater emphasis on the hosted-mode browser, which defers the need to run the GWT compiler until a later time, but that brings its own risks, particularly that of not catching issues with real browsers until much later than we'd like.

我们将开始改变我们的工作实践来缓解这个问题,包括更加强调托管模式浏览器,它将运行 GWT 编译器的需要推迟到以后,但这带来了它自己的风险,尤其是直到比我们想要的晚得多,才发现真实浏览器的问题。

Ideally, we'd like to make the GWT compiler itself quicker - a minute to compile a fairly small application is taking the piss. However, we are using the compile if a fairly naive fashion, so I'm hoping we can make some quick and easy gains.

理想情况下,我们想让 GWT 编译器本身更快 - 编译一个相当小的应用程序需要一分钟。但是,我们正在使用 compile 如果一种相当天真的方式,所以我希望我们可以快速轻松地获得一些收益。

We're currently invoking com.google.gwt.dev.Compiler as a java application from ant Ant target, with 256m max heap and lots of stack space. The compiler is launched by Ant using fork=true and the latest Java 6 JRE, to try and take advantage of Java6's improved performance. We pass our main controller class to the compiler along with the application classpath, and off it goes.

我们目前正在调用 com.google.gwt.dev.Compiler 作为来自 ant Ant 目标的 java 应用程序,具有 256m 最大堆和大量堆栈空间。编译器由 Ant 使用 fork=true 和最新的 Java 6 JRE 启动,以尝试利用 Java6 改进的性能。我们将主控制器类与应用程序类路径一起传递给编译器,然后就可以了。

What else can we do to get some extra speed? Can we give it more information so it spends less time doing discovery of what to do?

我们还能做些什么来获得额外的速度?我们能不能给它更多的信息,让它花更少的时间去发现要做什么?

I know we can tell it to only compile for one browser, but we need to do multi-browser testing, so that's not really practical.

我知道我们可以告诉它只为一个浏览器编译,但是我们需要做多浏览器测试,所以这不太实用。

All suggestions welcome at this point.

此时欢迎所有建议。

采纳答案by Yuval Adam

Let's start with the uncomfortable truth: GWT compiler performance is really lousy. You can use some hacks here and there, but you're not going to get significantly better performance.

让我们从一个令人不安的事实开始:GWT 编译器的性能真的很糟糕。你可以在这里和那里使用一些技巧,但你不会获得明显更好的性能。

A nice performance hack you can do is to compile for only specific browsers, by inserting the following line in your gwt.xml:

您可以做的一个很好的性能技巧是仅针对特定浏览器进行编译,方法是在您的gwt.xml.

<define-property name="user.agent" values="ie6,gecko,gecko1_8"></define-property>

or in gwt 2.x syntax, and for one browser only:

或使用 gwt 2.x 语法,并且仅适用于一个浏览器:

<set-property name="user.agent" value="gecko1_8"/>

This, for example, will compile your application for IE and FF only. If you know you are using only a specific browser for testing, you can use this little hack.

例如,这将仅为 IE 和 FF 编译您的应用程序。如果你知道你只使用特定的浏览器进行测试,你可以使用这个小技巧。

Another option: if you are using several locales, and again using only one for testing, you can comment them all out so that GWT will use the default locale, this shaves off some additional overhead from compile time.

另一种选择:如果您使用多个区域设置,并且再次仅使用一个进行测试,您可以将它们全部注释掉,以便 GWT 将使用默认区域设置,这会减少编译时的一些额外开销。

Bottom line: you're not going to get order-of-magnitude increase in compiler performance, but taking several relaxations, you can shave off a few minutes here and there.

底线:您不会在编译器性能上获得数量级的提升,但是如果稍微放松一下,您就可以在这里和那里节省几分钟的时间。

回答by Dave Webb

The GWT compiler is doing a lot of code analysis so it is going to be difficult to speed it up. This session from Google IO 2008will give you a good idea of what GWT is doing and why it does take so long.

GWT 编译器会进行大量代码分析,因此很难对其进行加速。 这个来自 Google IO 2008 的会议将让您很好地了解 GWT 正在做什么以及为什么它需要这么长时间。

My recommendation is for development use Hosted Mode as much as possible and then only compile when you want to do your testing. This does sound like the solution you've come to already, but basically that's why Hosted Mode is there (well, that and debugging).

我的建议是尽可能多地使用托管模式进行开发,然后仅在您想要进行测试时才进行编译。这听起来确实像您已经找到的解决方案,但基本上这就是托管模式存在的原因(嗯,那个和调试)。

You can speed up the GWT compile but only compiling for some browsers, rather than 5 kinds which GWT does by default. If you want to use Hosted Mode make sure you compile for at least two browsers; if you compile for a single browser then the browser detection code is optimised away and then Hosted Mode doesn't work any more.

您可以加快 GWT 编译速度,但只能针对某些浏览器进行编译,而不是 GWT 默认执行的 5 种。如果要使用托管模式,请确保至少为两个浏览器编译;如果您为单个浏览器编译,则浏览器检测代码将被优化掉,然后托管模式不再起作用。

An easy way to configure compiling for fewer browsers is to create a second module which inherits from your main module:

为更少的浏览器配置编译的一种简单方法是创建从主模块继承的第二个模块:

<module rename-to="myproject">
  <inherits name="com.mycompany.MyProject"/>
  <!-- Compile for IE and Chrome -->
  <!-- If you compile for only one browser, the browser detection javascript
       is optimised away and then Hosted Mode doesn't work -->
  <set-property name="user.agent" value="ie6,safari"/>
</module>

If the rename-toattribute is set the same then the output files will be same as if you did a full compile

如果rename-to属性设置相同,则输出文件将与您进行完整编译时相同

回答by Robert Munteanu

  • Split your application into multiple modules or entry points and re-compile then only when needed.
  • Analyse your application using the trunk version - which provides the Story of your compile. This may or may not be relevant to the 1.6 compiler but it can indicate what's going on.
  • 将您的应用程序拆分为多个模块或入口点,然后仅在需要时重新编译。
  • 使用主干版本分析您的应用程序——它提供了您编译故事。这可能与 1.6 编译器相关,也可能不相关,但它可以表明发生了什么。

回答by Chi

If you run the GWT compiler with the -localWorkers flag, the compiler will compile multiple permutations in parallel. This lets you use all the cores of a multi-core machine, for example -localWorkers 2 will tell the compiler to do compile two permutations in parallel. You won't get order of magnitudes differences (not everything in the compiler is parallelizable) but it is still a noticable speedup if you are compiling multiple permutations.

如果使用 -localWorkers 标志运行 GWT 编译器,编译器将并行编译多个排列。这让您可以使用多核机器的所有内核,例如 -localWorkers 2 将告诉编译器并行编译两个排列。您不会获得数量级差异(并非编译器中的所有内容都是可并行化的),但如果您正在编译多个排列,它仍然是一个显着的加速。

If you're willing to use the trunk version of GWT, you'll be able to use hosted mode for any browser (out of process hosted mode), which alleviates most of the current issues with hosted mode. That seems to be where the GWT is going - always develop with hosted mode, since compiles aren't likely to get magnitudes faster.

如果您愿意使用 GWT 的主干版本,您将能够对任何浏览器使用托管模式(进程外托管模式),这可以缓解当前托管模式的大部分问题。这似乎是 GWT 的发展方向 - 始终使用托管模式进行开发,因为编译不太可能更快。

回答by monzonj

Although this entry is quite old and most of you probably already know, I think it's worth mention that GWT 2.x includes a new compile flag which speeds up compiles by skipping optimizations. You definitely shouldn't deploy JavaScript compiled that way, but it can be a time saver during non-production continuous builds.

虽然这个条目很旧而且你们中的大多数人可能已经知道,但我认为值得一提的是 GWT 2.x 包含一个新的编译标志,它通过跳过优化来加速编译。您绝对不应该部署以这种方式编译的 JavaScript,但它可以在非生产连续构建期间节省时间。

Just include the flag: -draftCompile to your GWT compiler line.

只需将标志:-draftCompile 添加到您的 GWT 编译器行即可。

回答by CCarpo

For GWT 2.x I just discovered that if you use

对于 GWT 2.x 我刚刚发现如果你使用

<set-property name="user.agent" value="ie6"/>
<extend-property values="ie8,gecko1_8" name="user.agent"/>

You can even specify more than one permutation.

您甚至可以指定多个排列。

回答by Stephen

Here is a list of user.agent valuesyou can set it to.

这是您可以将其设置为的 user.agent 值列表

(Adding this here because I keep ending up here when I search for what I should set to make it only produce a permutation for chrome. Answer is: <set-property name="user.agent" value="safari"/>)

(因为我一直在结束了这里的时候,我搜索我应该设置,使其只生产一个置换镀铬这里添加此答案是:。 <set-property name="user.agent" value="safari"/>

回答by Chi

In the newer versions of GWT (starting either 2.3 or 2.4, i believe), you can also add

在较新版本的 GWT 中(我相信从 2.3 或 2.4 开始),您还可以添加

<collapse-all-properties />

to your gwt.xml for development purposes. That will tell the GWT compiler to create a single permutation which covers all locales and browsers. Therefore, you can still test in all browsers and languages, but are still only compiling a single permutation

到您的 gwt.xml 用于开发目的。这将告诉 GWT 编译器创建一个覆盖所有语言环境和浏览器的排列。因此,您仍然可以在所有浏览器和语言中进行测试,但仍然只编译一个排列

回答by martins.tuga

You can add one option to your build for production:

您可以为生产添加一个选项:

-localWorkers 8– Where 8 is the number of concurrent threads that calculate permutations. All you have to do is to adjust this number to the number that is more convenient to you. See GWT compilation performance(thanks to Dennis Ich comment).

-localWorkers 8– 其中 8 是计算排列的并发线程数。您所要做的就是将此数字调整为对您更方便的数字。请参阅GWT 编译性能(感谢 Dennis Ich 评论)。

If you are compiling to the testing environment, you can also use:

如果是编译到测试环境,还可以使用:

-draftCompilewhich enables faster, but less-optimized compilations

-draftCompile这可以实现更快但优化程度较低的编译

-optimize 0which does not optimize your code (9 is the max optimization value)

-optimize 0这不会优化您的代码(9 是最大优化值)

Another thing that more than doubled the build and hosted mode performance was the use of an SSD disk (now hostedmode works like a charm). It's not an cheap solution, but depending on how much you use GWT and the cost of your time, it may worth it!

另一件使构建和托管模式性能提高一倍以上的事情是使用 SSD 磁盘(现在托管模式非常有用)。这不是一个便宜的解决方案,但取决于您使用 GWT 的数量和时间成本,它可能值得!

Hope this helps you!

希望这对你有帮助!