What should I do to investigate and troubleshoot a slow compilation problem?
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:
- 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.
UPDATE
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));
}
}
If the slow
method is commented out, the compilation time is back to normal.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…