Troubleshoot slow compilation

萝らか妹 提交于 2019-11-28 23:15:04
assylias

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

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.

csgeek

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

Initial discussion:

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!