Is merging classes with ProGuard recommended on Android/Dalvik?

送分小仙女□ 提交于 2019-12-12 11:55:36

问题


It just occurred to me that one of the ProGuard code optimizations we used, namely merging class hierarchies, may perhaps not be a good choice at all.

My hunch was that it would be beneficial to merge classes in order to cut down on invocations of the ClassLoader, which at least on a JVM is a particularly slow operation, and in our code we opted for many smaller (often inner) classes rather than large God object classes, so the ClassLoader will run relatively often.

However, given the extreme (probably unlikely) case that all classes would be merged into a single one, then even though the loader would only be invoked once, we would end up loading tons of code into memory that will very likely be never used (80/20 rule applies here as well I guess).

That leaves me wondering:

1) How fast is class loading in Dalvik actually? Is it an operation that is worth cutting down on by using class merging at all?

2) That said, would you recommend using class merging at all on Android?


回答1:


Vertical class merging collapses classes/interfaces with their extensions/implementations when these are needlessly split. That should always be an improvement (size and performance).

For horizontal class merging, I can't provide a general answer. The code base will be smaller, but some code could conceivably be loaded to soon, or in the extreme, unnecessarily.



来源:https://stackoverflow.com/questions/11329637/is-merging-classes-with-proguard-recommended-on-android-dalvik

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!