英文:
Does AspectJ (Mojo's Maven Plugin in particular) perform optimization?
问题
我正在对一个使用Mojo的AspectJ Maven插件的简单应用程序进行基准测试。我注意到,仅通过在我的pom.xml中包含aspectj依赖项,基准程序的运行速度提高了3倍。
<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> <!-- use this goal to weave all your test classes -->
</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>
我的基准测试包含许多简单的循环,例如:
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;
}
}
当我删除这些循环时,我没有观察到相同的加速效果。是否有人遇到类似的经验?是不是AspectJ/Mojo的插件由于某种原因对这样的循环执行了优化?
英文:
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?
专注分享java语言的经验与见解,让所有开发者获益!
评论