siom79 / japicmp

Comparison of two versions of a jar archive
https://siom79.github.io/japicmp
Apache License 2.0
712 stars 107 forks source link

Improve memory consumption #318

Closed zentol closed 2 years ago

zentol commented 2 years ago

The JarArchiveComparator keeps way more stuff in memory than it would actually need, and it has caused some issues in our CI pipeline due to memory/GC issues.

It first loads every class from 2 jars into memory into both the javassist ClassPool and a LinkedList, and then applies the filters to create another list of filtered classes.

Instead, we could apply the filters right away within createListOfCtClasses. Classes that did not pass the filter should also be removed from the ClassPool, which can be done by creating a subclass like this:

public class MyClassPool extends ClassPool {
  public void remove(CtClass ctClass) {
    removeCached(ctClass.getName());
  }
}