answersLogoWhite

0

Actually, the Java compiler is not considered slow when compared to compiling a similar project in C or C++. The Java compiler itself is actually quite simple. All of the fancy Java optimizations occur during runtime.

As someone who used to work on the Sun JDK at Sun itself, I can tell you that the old javac (pre-2010 or so) was rather simplistic. Remember that javac itself is a Java program, so that to run, it must first invoke a JVM, and incurs typical JVM load and initialization time. It was originally designed to work on the 'fork/exec' model so common to UNIX, where it would fork a new instance of javac (and the associated JVM required to run it) for every file that it compiled. Now, creating a new JVM had significant startup time costs (initialization of methods was nontrivial), but javac would run reasonably fast one that happened. However, having to fork several hundred times during a single project compile got expensive, and slow. This was particularly true on Windows, where a 'fork/exec' call is over 10x as slow as on a UNIX or Linux system.

So, the 'old' javac, while quite quick to actually compile a single file after it got running, was actually quite slow overall when forced to compile a large number of source code files.

A major revamp of the javac compiler was undertaken during 2010 with JDK 7. This revamp significantly reduced the number of times a fork/exec was done, buy reusing existing JVMs to run several (sequential) invocations of the javac language. This significantly improved large project compile times, as it reduced the primary overhead that was slowing things down. There are additional projects being worked on that will turn javac into a single multi-threaded program able to compile multiple files itself in one invocation, thus eliminating the need to spawn multiple JVMs. This will particularly help Windows compiles, as Windows threading is much faster than fork/exec.

So, overall, if you are running a JDK with a javac created BEFORE mid-2010, javac will be relatively slow for compiling lots of source files, and worse on Windows. Pretty much all Sun/Oracle JDK 6 versions (even the newest ones) have this "defective" javac. The newer, faster javac is available in JDK 7 - I believe it may not be in JDK7, but is definitely in JDK 7 Update 1 and later. This javac should feel quite responsive for most projects, and only be a bit slow on large Windows compiles (more than 100 source files or so), and, even there, will be a noticeable improvement over the JDK 6 javac program.

User Avatar

Wiki User

12y ago

What else can I help you with?