views:

284

answers:

6

Does obfuscating a Java program affect its performance (excluding renaming things)?

+1  A: 

No. Obfuscation simply replaces your sensibly named code with urneadable one. In some cases (as an example when using ProGuard, our code may even be "optimized", by removing all useless code blocks (such as if(false) and look-alike statements).

EDIT (to clarify Magesh ideas).

When using an obfuscator (and NOT obfuscating by hand, which is not a good idea), it will load your classes and inline some methods, or code blocks (like the aforementionned if) to simplify code for obtained big blocks of code. As a consequence, there are less method calls, requiring less stack usage, and then fastening the application.

The other thing an obfuscator usually does it to rename all variables from mySmartVariable to a$a$a, making impossible to de-compile (since a java decompiler considers $ as the symbol used to identify inner and anonymous classes, and not variables).

Riduidel
but adding an empty methods might make it slow right ?
Magesh
@Magesh It removes, not adds useless code blocks.
James
@James, not always, see my answer. Some software adds meaningless control flows so the code is much harder to read, e.g. flow obfuscation. That does have an impact on performance, though small.
Razzie
@james yes i meant the flow obfuscation.
Magesh
+3  A: 

Most definitely yes: except in the simplest case where only identifier names are scrambled, it's only a matter of how much performance is affected. More details for example here, general information about obfuscation techniques is available in the Obfuscated code Wikipedia article.

Tomislav Nakic-Alfirevic
+1  A: 

If you add redundant code that doesn't ever get traversed, no. If you add logic that must be traversed in the normal execution of your code then, yes, it will affect performance. How much depends on what illogical structure you've attempted to add to confuse would be software pirates.

wheaties
+1  A: 

Sometimes, yes. In Java ME (the "mobile phone version" of Java), obfuscation works on the compiled byte code, and (among other things) replaces names with short, auto-generated ones. This makes the byte code shorter, which at least makes it faster to download the application over the network.

Thomas Padron-McCarthy
A: 

And all that for something that doesn't do anything anyway :)

jwenting
lol.! good answer
Magesh
+2  A: 

In general, obfuscation by renaming variables, methods, and classnames to more meaningless names does not impact performance. Some vendors of obfuscation software even claim that aside from obfuscation, there is also a performance gain as much as 30%. Although I have never tested these claims, have never seen them proven, and therefore find them hard to believe.

However, do keep in mind that some software also enables flow obfuscation: adding meaningless control loops to statements so the code is harder to follow. That does have a negative effect on performance, albeit small.

Razzie
Interesting point (really, no joke here), Razzie. I wonder what is the interest since, once involving obfuscation, you consider your code in hostile hands that can use code analysis tools to remove empty methods and inline 1-called methods ...
Riduidel
Good obfuscators can produce totally unreadable code, using goto's and other garbage, resulting in code that is very hard to decompile (well). This comes with a performance penalty though. Take a look at http://www.excelsior-usa.com/articles/java-obfuscators.html#performance, interesting read.
Razzie