排除慢速编译问题 [英] Troubleshoot slow compilation

查看:218
本文介绍了排除慢速编译问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该如何调查和解决缓慢的编译问题

我的项目有大约100个类,需要超过45秒编译,这对我来说似乎很慢。作为参考,我有另一个项目,有50个类,在3秒内编译。

My project has about 100 classes and takes more than 45 seconds to compile, which seems very slow to me. As a reference, I have another project with 50 classes that compiles in 3 seconds.

ps:


  • 我使用maven作为构建工具。需要maven〜50秒来编译( mvn clean compile ),其中45秒用于运行javac(通过运行 -X 选项)。

  • 增加内存量没有帮助( -Xms500m

  • 我可以提供更多关于我的项目的信息,但它是相当标准,所以我不知道什么信息是相关的。

  • I use maven as a build tool. It takes maven ~50 seconds to compile (mvn clean compile), of which 45 seconds are spent running javac (confirmed by running with the -X option).
  • increasing the amount of memory did not help (-Xms500m)
  • I can give more info about my project but it is fairly standard so I'm not sure what information is relevant.

感谢Tagir的想法,我找到了一个罪魁祸首。这个类增加了20秒的编译时间:

Thanks to Tagir's idea I've managed to find one of the culprits. This class adds 20 seconds to the compilation time:

import org.jooq.DSLContext;
import org.jooq.Field;
import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.round;
import static org.jooq.impl.DSL.sum;


class Test {
  static Object fast(DSLContext sql) {
    Field<Double> a = field("a").cast(Double.class);
    return sql.select()
            .having(round(sum(a).cast(Double.class), 2).ne(0d));
  }
  static Object slow(DSLContext sql) {
    return sql.select()
            .having(round(sum(field("a").cast(Double.class)).cast(Double.class), 2).ne(0d));
  }
}

如果 slow 方法注释掉,编译时间恢复正常。

If the slow method is commented out, the compilation time is back to normal.

推荐答案

>

您可以先重新创建一个空项目,然后逐个添加软件包,直到编译时间受到影响为止 - 这将有助于识别导致问题的软件包。

Troubleshooting - general approach

You can start by recreating an empty project and add packages back one by one until the compilation time is affected - that should help you identify the package that is causing the problem.

然后,您可以删除包中的所有类,并逐个添加 - 这应该可以帮助您找到导致问题的类。

You can then remove all classes in the package and add them back one by one - that should help you find the classes that cause the issue.

然后,您可以从每个类中删除所有方法,并逐个添加它们,直到您看到编译时间增加(您可以节省时间只重新编译那一个类)。

You can then remove all the methods from each of those classes and add them back one by one until you see the compilation time increase (you can save time by only recompiling that one class).

在这种情况下,似乎根本原因是javac中的一个错误,所以我提交了一个错误报告,该报告已标记为JEP 215: javac的分层属性和要在Java 9上修复的目标。

In this case it seems that the root cause is a bug in javac so I have filed a bug report which has been marked as a duplicate of "JEP 215: Tiered Attribution for javac" with a target to be fixed on Java 9.

同时,解决方法是在嵌套泛型方法调用使用通用类型推理,但不幸的是,并不总是工作...

In the meantime, the workaround is to introduce local variables when there are nested generic method calls that use generic type inference, but unfortunately that does not always work...

这篇关于排除慢速编译问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆