JDK-8043253 : Slow javac compile times in JDK 8
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2014-05-15
  • Updated: 2014-07-29
  • Resolved: 2014-06-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u20Fixed 9 b20Fixed
Description
FULL PRODUCT VERSION :
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

EXTRA RELEVANT SYSTEM CONFIGURATION :
Core i7 860 2.8Ghz
12GB RAM
C: is an 335GB SSD disk 25% of space used

A DESCRIPTION OF THE PROBLEM :
I compare the time javac 1.7.0_55  and javac 1.8.0_05 use to compile a .java file.
javac 8 use 6 seconds where javac 7 uses 1.5 seconds.

This is a problem for us since the attached test code is a tiny example of the code we generate and compile using the Compiler API while running our program, and while the user is waiting. 
We compile it because we expect it to be evaluated many times.
We compile many thousands of this size of functions.

REGRESSION.  Last worked in version 7u55

ADDITIONAL REGRESSION INFORMATION: 
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I used this in a .bat file to time the compile process.
--
echo %time%

cmd /c "C:\Program Files\Java\jdk1.7.0_55\bin\javac.exe" C:\test\TestClass.java

echo %time%

cmd /c "C:\Program Files\Java\jdk1.8.0_05\bin\javac.exe" C:\test\TestClass.java

echo %time%
--

Summary of the result I get is: 
java7 1.5s 
java8 6s
e.g. Javac8 is a factor of 4 slower.



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect javac 7 and 8 to be same speed for java7 source code
ACTUAL -
javac 7 is a factor 4 faster than javac 8

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
<< attaching source file >>

---------- END SOURCE ----------


Comments
Delaying diagnostic position generation yields the following results: BEFORE: real 0m6.047s user 0m14.842s sys 0m0.419s AFTER: real 0m1.827s user 0m8.690s sys 0m0.370s In other words, compilation time goes back to JDK 7 levels.
17-06-2014

Culprit of this performance regression is that lots of diagnostic objects are created in the middle of operator resolution; note that the position is only needed when compressing a method resolution diagnostic - i.e. to show something like: /home/maurizio/Desktop/Main.java:51: error: incompatible types: int cannot be converted to String m(1); ^ Instead of: /home/maurizio/Desktop/Main.java:51: error: method m in class Test cannot be applied to given types; m(1); ^ required: String found: int reason: argument mismatch; int cannot be converted to String Now, it's important to notice that these compressed diagnostics are not generated for operators - i.e. Resolve special cases operator diagnostics in a different way. As such there's never a real need to have positions attached to operator overload errors, as this position will be discarded anyway. There are two possible ways to tackle this problem: - defer position creation until when diagnostics actually have to be displayed - tweak overload resolution so that position is set to null during operator overload resolution
17-06-2014

original source file attached. Test run from windows 7 : C:\Users\sc87771\Desktop>echo 18:37:30.14 18:37:30.14 C:\Users\sc87771\Desktop>cmd /c C:\jdk1.7.0_51\bin\javac TestClass.java C:\Users\sc87771\Desktop>echo 18:37:32.26 18:37:32.26 C:\Users\sc87771\Desktop>cmd /c C:\jdk8\bin\javac TestClass.java C:\Users\sc87771\Desktop>echo 18:37:39.37 18:37:39.37 C:\Users\sc87771\Desktop>cmd /c C:\jdk1.9.0\bin\javac TestClass.java C:\Users\sc87771\Desktop>echo 18:37:46.05 18:37:46.05 C:\Users\sc87771\Desktop>cat test.bat echo %time% cmd /c C:\jdk1.7.0_51\bin\javac TestClass.java echo %time% cmd /c C:\jdk8\bin\javac TestClass.java echo %time% cmd /c C:\jdk1.9.0\bin\javac TestClass.java echo %time%
15-05-2014