2

I am benchmarking a simple application that makes use of Mojo's AspectJ Maven Plugin. I noticed that just by including the aspectj dependencies in my pom.xml, the benchmark program runs 3x faster.

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <aspectj.version>1.8.13</aspectj.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.8.13</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.8.13</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjtools</artifactId>
            <version>1.8.13</version>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.11</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>       <!-- use this goal to weave all your main classes -->
<!--                            <goal>test-compile</goal>  &lt;!&ndash; use this goal to weave all your test classes &ndash;&gt;-->
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjrt</artifactId>
                        <version>1.8.13</version>
                    </dependency>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjtools</artifactId>
                        <version>1.8.13</version>
                    </dependency>

                </dependencies>
                <configuration>
                    <complianceLevel>1.8</complianceLevel>
                    <source>1.8</source>
                    <target>1.8</target>
                    <forceAjcCompile>true</forceAjcCompile>
                    <showWeaveInfo>true</showWeaveInfo>
                    <verbose>true</verbose>
                    <Xlint>ignore</Xlint>
                    <encoding>UTF-8</encoding>
                </configuration>

            </plugin>
        </plugins>
    </build>

My benchmark consists of a lot of simple loops such as:

        long res = 0;
        for(int i = 0; i < 1000; i++){
            for(int j = 0; j < 1000; j++){
                res += i*j + i*i + j*j*j;
            }
       }

When I remove these loops I do not observe the same speedup effect. Has anyone encountered similar experiences? Does AspectJ/Mojo's plugin for some reason perform optimizations on loops like this?

starboost
  • 93
  • 1
  • 3
  • This is interesting. Can you show the timings? – user Jun 05 '20 at 15:32
  • 1
    My benchmark has about 375,000 method calls. Without the plugin it takes 61740ms on an average from 10 runs. With the plugin the avg time is 23313ms. – starboost Jun 05 '20 at 17:31
  • Please make the issue reproducible by posting a simplified version of your project on GitHub. This is called an [MCVE](https://stackoverflow.com/help/mcve) and the correct way of asking questions like this one if you do not wish to just attract speculation. You did not even mention if your benchmark applies aspects to the code or not. If so, I want to see those aspects. AspectJ Maven Plugin only dispatches compilation to the AspectJ compiler which is an aspect-enhanced and regularly upstream-updated fork of the Eclipse Java compiler. – kriegaex Jun 08 '20 at 03:44

0 Answers0