android – Effect of apk size on startup speed


If you throw in different libraries, then the size of the compiled code increases greatly, that is, the classes.dex in the apk grows.

Does the speed of calling a piece of code at the start of a killed application depend on the size of the apk, or will the system simply take the necessary method from the dalwick cache and start its execution without working with the full image?

That is, if I make an application with 15 MB of code, will BroadcastReceivers start slower in it than in an application with 20 KB of code?

What about ART?


I don’t know the exact details, but as far as I understand, the loading time will depend not on the size of the apk, but on the number and size of classes and resources used for and before showing the first screen. Classes are loaded only as they are used, that is, as long as your code does not use any methods, constants, or anything else from the class, this class will not be loaded into memory. It's the same with resources. So if you cram a bunch of libs and don’t use them in any way and they don’t have any auto-starting services or something else in their manifests, then if they affect the startup speed, then by some hundredths of a percent.

If you look at the implementation of BaseDexClassLoader in the android sources , you can see that it loads classes through DexPathList , which is essentially just a list of DexFile . Unfortunately, DexFile does not contain a code that would show exactly how it opens the apk file and how exactly it loads a specific class, these methods are implemented natively and I don’t know where you can look at their sort, so it’s possible that when you open a dex file from apk, it’s entirely is loaded into memory, and the loading method of a particular class already unwraps this class from there.

Scroll to Top