混淆会影响性能吗?
混淆 Java 程序是否会影响其性能(不包括重命名)?
Does obfuscating a Java program affect its performance (excluding renaming things)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
混淆 Java 程序是否会影响其性能(不包括重命名)?
Does obfuscating a Java program affect its performance (excluding renaming things)?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
绝对是的:除了在最简单的情况下(仅对标识符名称进行加扰)之外,这只是影响性能的问题。更多详细信息,例如此处,有关混淆技术的一般信息可在混淆代码 维基百科文章。
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.
一般来说,通过将变量、方法和类名重命名为更无意义的名称来进行混淆不会影响性能。一些混淆软件厂商甚至声称,除了混淆之外,还有高达30%的性能提升。尽管我从未测试过这些说法,也从未见过它们被证实,因此觉得它们很难相信。
但是,请记住,某些软件还可以进行流程混淆:向语句添加无意义的控制循环,使代码更难以理解。这确实会对性能产生负面影响,尽管影响很小。
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.
不会。混淆只是将您合理命名的代码替换为不可读的代码。在某些情况下(例如,使用 ProGuard 时,我们的代码甚至可以通过删除所有无用的代码块(例如
if(false)
和类似的语句)来“优化”。编辑(澄清 Magesh 的想法)。
当使用混淆器(而不是手动混淆,这不是一个好主意)时,它将加载您的类并内联一些方法或代码块(如前面提到的 if)。简化获得的大代码块的代码,从而减少方法调用,需要更少的堆栈使用,然后
混淆器通常会重命名 mySmartVariable 中的所有变量。 code> 到
a$a$a
,使得无法反编译(因为 java 反编译器将$
视为用于识别内部类和匿名类的符号,而不是变量)。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
toa$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.
有时,是的。在 Java ME(Java 的“手机版本”)中,混淆作用于已编译的字节码,并且(除其他外)用简短的自动生成的名称替换名称。这使得字节码更短,这至少使得通过网络下载应用程序的速度更快。
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.