mstrobel/procyon

Questionable performance

SimplyProgrammer opened this issue · 1 comments

Hello!
I have been working on one application that is supposed to deobfuscate java source code to be more specific, to deobfuscate Minecraft mods. Recently I have decided that it would be a nice feature to be able to process jar files directly without the necessity of using external software so I decided to use your decompiler to fulfill this purpose!

The task is simple. All that I need is to turn .class file into .java file (decompile it). So I have created a function that will read a class file and return it as source:

public static final DecompilerSettings DECOMP_SETTINGS = DecompilerSettings.javaDefaults();

private String decompile(String sourcePath)
{
if (!sourcePath.endsWith(".class"))
	return null;

//double t0 = System.nanoTime();

StringWriter sw = new StringWriter();
Decompiler.decompile(sourcePath, new PlainTextOutput(sw), DECOMP_SETTINGS);
String result = sw.toString();

//double t = System.nanoTime();
//System.out.println((t-t0)/1000000);
return result;
}

The returned string is then written back into file but this process is not slow!

However, I soon found a problem, since I need to decompile a lot of classes I need it to be fast!
So I have decided to create a simple benchmark (commented code) and found out that to decompile one simple class approximately 13kB and not even 250 lines of code it needs approximately 1.9 sec! Don't get me wrong! It may sounds like a good score but in fact, that's actually terrible... Especially when I need to decompile 1000 of classes like that or even bigger!

I think there must be something that I am doing wrong, also the fact that this site http://www.javadecompilers.com/ that proclaims to use Procyon as well can decompile pretty big jars almost 10x faster than my implementation which just confirms my thought!

So the question is what am I doing wrong or are there any performance tips or improvements I should consider?
Please help! I would really like to cut that time at last in half!

Thank you!

The problem might be that you're only processing a single class per run, as opposed to decompiling all the classes in a single run. Decompiling even a single class involves a lot of work that is best performed just once, like resolving all of a class's base types and interfaces, and loading some common JDK classes. And then there's the warmup issue (java methods aren't immediately optimized or JIT compiled, depending on your JVM; they might initially run in interpreted mode).