Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimizing Java compiler during a Maven build?

I have a Maven profile for a Java project that is activated when doing a final build on a Hudson CI server.

Currently this profile's only customization is to the Maven compiler plugin as follows:

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <debug>false</debug>
                        <optimize>true</optimize>
                    </configuration>
                </plugin>

Are there any other tweaks or optimizations to the Java compiler that a final build should be doing to maximize performance?

like image 533
HDave Avatar asked Nov 18 '10 19:11

HDave


People also ask

Which Java compiler does Maven use?

The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.

Does the Java compiler optimize?

The JVMs JIT compiler is one of the fascinating mechanisms on the Java platform. It optimizes your code for performance, without giving away its readability. Not only that, beyond the “static” optimization methods of inlining, it also makes decisions based on the way that the code performs in practice.

What is annotationProcessorPaths in Maven?

<annotationProcessorPaths>The detection itself depends on the configuration of annotationProcessors. Each classpath element is specified using their Maven coordinates (groupId, artifactId, version, classifier, type). Transitive dependencies are added automatically.


2 Answers

Assuming that you're running on the Sun (Hotspot) JVM, all optimization happens in the JVM.

So specifying <optimize>true</optimize> does nothing.

And specifying <debug>false</debug> simply removes debugging symbols. Which will slightly decrease your JARfile size, but make it much harder to track down production problems, because you won't have line numbers in your stack traces.


One thing that I would specify is JVM compatibility settings:

<source>1.6</source>
<target>1.6</target>
like image 57
Anon Avatar answered Sep 28 '22 03:09

Anon


You shouldn't even do that - optimization in javac has been disabled for quite a while, IIRC. Basically the JIT is responsible for almost all the optimization, and the javac optimizations actually hurt that in some cases.

If you're looking to tune performance you should look elsewhere:

  • Your actual code
  • VM options (e.g. GC tuning)
like image 24
Jon Skeet Avatar answered Sep 28 '22 02:09

Jon Skeet