AspectJ(特别是Mojo的Maven插件)是否执行优化?

huangapple 未分类评论53阅读模式
英文:

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.

    &lt;properties&gt;
        &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
        &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
        &lt;aspectj.version&gt;1.8.13&lt;/aspectj.version&gt;
    &lt;/properties&gt;

    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
            &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt;
            &lt;version&gt;1.8.13&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
            &lt;artifactId&gt;aspectjweaver&lt;/artifactId&gt;
            &lt;version&gt;1.8.13&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
            &lt;artifactId&gt;aspectjtools&lt;/artifactId&gt;
            &lt;version&gt;1.8.13&lt;/version&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;


    &lt;build&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                &lt;artifactId&gt;aspectj-maven-plugin&lt;/artifactId&gt;
                &lt;version&gt;1.11&lt;/version&gt;
                &lt;executions&gt;
                    &lt;execution&gt;
                        &lt;goals&gt;
                            &lt;goal&gt;compile&lt;/goal&gt;       &lt;!-- use this goal to weave all your main classes --&gt;
&lt;!--                            &lt;goal&gt;test-compile&lt;/goal&gt;  &amp;lt;!&amp;ndash; use this goal to weave all your test classes &amp;ndash;&amp;gt;--&gt;
                        &lt;/goals&gt;
                    &lt;/execution&gt;
                &lt;/executions&gt;
                &lt;dependencies&gt;
                    &lt;dependency&gt;
                        &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
                        &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt;
                        &lt;version&gt;1.8.13&lt;/version&gt;
                    &lt;/dependency&gt;
                    &lt;dependency&gt;
                        &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
                        &lt;artifactId&gt;aspectjtools&lt;/artifactId&gt;
                        &lt;version&gt;1.8.13&lt;/version&gt;
                    &lt;/dependency&gt;
                  
                &lt;/dependencies&gt;
                &lt;configuration&gt;
                    &lt;complianceLevel&gt;1.8&lt;/complianceLevel&gt;
                    &lt;source&gt;1.8&lt;/source&gt;
                    &lt;target&gt;1.8&lt;/target&gt;
                    &lt;forceAjcCompile&gt;true&lt;/forceAjcCompile&gt;
                    &lt;showWeaveInfo&gt;true&lt;/showWeaveInfo&gt;
                    &lt;verbose&gt;true&lt;/verbose&gt;
                    &lt;Xlint&gt;ignore&lt;/Xlint&gt;
                    &lt;encoding&gt;UTF-8&lt;/encoding&gt;
                &lt;/configuration&gt;

            &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/build&gt;

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

        long res = 0;
        for(int i = 0; i &lt; 1000; i++){
            for(int j = 0; j &lt; 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?

huangapple
  • 本文由 发表于 2020年6月5日 23:31:03
  • 转载请务必保留本文链接:https://java.coder-hub.com/62218955.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定