objectionary / hone-maven-plugin

Maven plugin that applies a number of optimizations to your Bytecode, using EOLANG and 𝜑-calculus, trying to make it work faster
https://www.objectionary.com/hone-maven-plugin/
MIT License
3 stars 0 forks source link
bytecode-manipulation code-optimization eolang java maven-plugin

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.21</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: 6Mb (6Mb bytes, 156806 lines)
Size of .phi: 2Mb (2Mb bytes, 42165 lines)
Optimization time: 4min (210662 ms)
Available CPUs: 4

jeo-maven-plugin:unroll-phi 106.653
eo-maven-plugin:xmir-to-phi 84.875
eo-maven-plugin:phi-to-xmir 11.929
jeo-maven-plugin:disassemble 2.194
exec-maven-plugin:exec 1.007
jeo-maven-plugin:assemble 0.660

The results were calculated on 2024-11-02 at 16:46, on Linux.

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.

You may also want to run this (having GNU Make installed):

make quick

This will do exactly what is happening in Docker container, but without Docker. This may be a faster way to check how the pipeline works.

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