Is merging classes with ProGuard recommended on An

2019-06-24 23:53发布

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条回答
Lonely孤独者°
2楼-- · 2019-06-25 00:42

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.

查看更多
登录 后发表回答