我应该怎么做才能调查和解决慢速编译问题?
我的项目有大约100个类,编译时间超过45秒,这对我来说似乎很慢.作为参考,我有另外一个项目有50个类,在3秒内编译.
PS:
mvn clean compile),其中45秒用于运行javac(通过运行-X选项确认).-Xms500m)感谢Tagir的想法,我找到了其中一个罪魁祸首.该类为编译时间增加了20秒:
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));
}
}
Run Code Online (Sandbox Code Playgroud)
如果slow方法被注释掉,则编译时间恢复正常.