开发者

Does obfuscation affect performance?

Does obfuscating a Java prog开发者_JAVA技巧ram affect its performance (excluding renaming things)?


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.


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.


No. Obfuscation simply replaces your sensibly named code with an unreadable 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 aforementioned 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).


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜