Skip to content

Latest commit

 

History

History
149 lines (129 loc) · 6.08 KB

README.md

File metadata and controls

149 lines (129 loc) · 6.08 KB

Bytecode Optimizing Maven Plugin

mvn Maven Central Javadoc License Hits-of-Code Lines of code codecov

This Apache Maven plugin may optimize your Bytecode after compilation, to make it work faster. Just add this to your pom.xml file (you must have Docker installed too):

<project>
  [..]
  <build>
    <plugins>
      <plugin>
        <groupId>org.eolang</groupId>
        <artifactId>hone-maven-plugin</artifactId>
        <version>0.0.28</version>
        <executions>
          <execution>
            <goals>
              <goal>build</goal>
              <goal>optimize</goal>
              <goal>rmi</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

The plugin will do exactly the following:

  1. Take Bytecode .class files from the target/classes/ directory and copy all of them to the target/classes-before-hone/ directory (as a backup).
  2. Using jeo-maven-plugin, transform .class files to .xmir format, which is EO in XML, and place them into the target/generated-sources/jeo-disassemble/ directory.
  3. Using eo-maven-plugin, convert .xmir files to .phi files with 𝜑-calculus expressions, and place them into the target/generated-sources/phi/ directory.
  4. Using normalizer, apply a number of optimizations to 𝜑-calculus expressions in the .phi files and place new .phi files into the target/generated-sources/phi-optimized/ directory.
  5. Using eo-maven-plugin, convert .phi files back to .xmir files and place them into the target/generated-sources/unphi/ directory.
  6. Using jeo-maven-plugin, transform .xmir files back to Bytecode and place .class files into the target/classes/ directory.

The effect of the plugin should be performance-positive (your code should work faster) along with no functionality degradation (your code should work exactly the same as it worked before optimizations). If any of these is not true, submit a ticket, we will try to fix.

Benchmark

Here is the result of the latest processing of a large Java class from JNA:

Input: com/sun/jna/Pointer.class
Size of .class: 22Kb (22Kb bytes)
Size of .xmir after disassemble: 2Mb (2Mb bytes, 37641 lines)
Size of .phi: 2Mb (2Mb bytes, 52462 lines)
Size of .xmir after unphi: 7Mb (7Mb bytes, 189330 lines)
Optimization time: 3min (153311 ms)

jeo-maven-plugin:unroll-phi   80.017  53.26%
eo-maven-plugin:xmir-to-phi   51.476  34.26%
eo-maven-plugin:phi-to-xmir   14.468  9.63%
jeo-maven-plugin:disassemble  2.53    1.68%
exec-maven-plugin:exec        1.101   0.73%
jeo-maven-plugin:assemble     0.647   0.43%

The results were calculated in this GHA job on 2024-11-20 at 12:46, on Linux with 4 CPUs.

Here is the result of the latest optimization of itself:

to-phi.xsl                  11714  28.64%
add-refs.xsl                5202   12.72%
set-locators.xsl            3253   7.95%
stars-to-tuples.xsl         3093   7.56%
wrap-method-calls.xsl       2496   6.10%
vars-float-up.xsl           1554   3.80%
cti-adds-errors.xsl         1488   3.64%
wrap-bytes.xsl              1470   3.59%
explicit-data.xsl           1307   3.20%
resolve-aliases.xsl         1306   3.19%
atoms-with-bound-attrs.xsl  1150   2.81%
add-probes.xsl              1137   2.78%
add-default-package.xsl     1114   2.72%
expand-qqs.xsl              1068   2.61%
const-to-dataized.xsl       994    2.43%
expand-aliases.xsl          946    2.31%

The results were calculated in this GHA job, on 2024-11-20 at 13:01, on Linux with 4 CPUs. For the sake of brevity, we show only the first 16 lines.

How to Contribute

Fork repository, make changes, then send us a pull request. We will review your changes and apply them to the master branch shortly, provided they don't violate our quality standards. To avoid frustration, before sending us your pull request please run full Maven build:

mvn clean install -Pqulice

You will need Maven 3.3+, Java 11+, and Docker installed.

The versions of EO and JEO, that we use, are defined in the in-docker-pom.xml file.