Type inference exponential compilation performance
ella nekipelova
ella.nekipelova at oracle.com
Thu Sep 25 14:56:19 UTC 2014
Hello, dear team,
I have a question concerning the javac performance in resolving type
inference. I found that if there are more than three nested invocations
with type inference, compilation might take several minutes.
Consider this example:
class Test<T> {
Test obj;
Test(Test<T> other) { this.obj = other.obj; }
static <U> Test<U> m(Test<U> src) { return new Test<U>(src); }
public static void main(String argv[]) {
Test<String> c14 = m(new Test<>(m(new Test<>(m(new Test<>(m(new Test<>(m(new Test<>(m(new Test<>(m(new Test<>(m(new Test<>(m(new Test<>(m(new Test<>(m(new Test<>(m(new Test<>(m(new Test<>(m(new Test<>())))))))))))))))))))))))))));
}
}
I noticed that there is exponential growth, because for for 8
invocations it takes 20 sec, for 9 - 50 sec, for 10 invocations
compilation succeeds in about 3 minutes, but for 14 invocations, as in
the example, javac just hangs.
It's unlikely that any human developer will ever write such code, but
there are different kinds of code generators, and we can't be sure about
their implementation.
My question is if this behavior is admissible? Are you going to do
anything to improve this situation?
Thank you,
Ella
More information about the compiler-dev
mailing list