Troubleshoot slow compilation

前端 未结 3 1038
野性不改
野性不改 2020-12-15 05:36

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 compi

相关标签:
3条回答
  • 2020-12-15 06:01

    One not so well known feature of Java 8 is Generalized Target-Type Inference.

    While it allows to write clearer code, this requires more work for Javac. Sometimes this results in exponential complexity of the type inference problem. This is a known issue, but unfortunately still unresolved - see JDK-8055984, JDK-8067767.

    The workaround is to compile at Java 7-compatibility level: javac -source 7, or just to use simpler constructions.

    0 讨论(0)
  • 2020-12-15 06:06

    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).

    Specific cause

    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...

    0 讨论(0)
  • 2020-12-15 06:06

    There was multiple discussions related to this. Adding these references in case anyone else stumbles upon this post.

    Initial discussion:

    • https://groups.google.com/forum/#!topic/jooq-user/grv6Wu_sFtA
    • Slow compilation with jOOQ 3.6+, plain SQL, and the javac compiler

    In my case I essentially tried to use auto-generated code as much as possible. Alternatively you can try the suggestion that Lukas mentions in this StackOverflow post linked above.

    0 讨论(0)
提交回复
热议问题