Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to calculate the contribution of each class to the dex #871

Open
hailuo966 opened this issue Jun 7, 2023 · 2 comments
Open

How to calculate the contribution of each class to the dex #871

hailuo966 opened this issue Jun 7, 2023 · 2 comments

Comments

@hailuo966
Copy link

Can I use baksmali.jar to calculate the contribution of each class to the dex file size?
Or how can I calculate the contribution of each class to the dex file size?
Thanks a lot.

@CunningLogic
Copy link

Complex question, the actual size will vary, certain data can be shared between classes.

For instance, strings, two classes may have the same strings within, but you only get on entry into the string index table.

and some compilers use space saving tricks, such as if two methods have identical dubug info items, they with only write one and and set the debug_info_off to the same offset.

With such data sharing, how do you calculate the size contribution?

@Lanchon
Copy link
Contributor

Lanchon commented Jul 3, 2023

java class files have a lot of redundancy, especially when they cross-link (eg: when they are part of the same program). java class files are heavily processed during class loading and the VMs are expected to have a very different and more compact representation in memory after loading, with much of this redundancy reduced.

dex files were designed for low memory devices and structured in such a way that they are ready for VM interpretation straight out of the file contents. they can simply be memory mapped and interpreted from there. so much of the java class loader processing needed to load java class files into memory is already done at dex build time when the dex file is constructed. redundancy is reduced and data is shared among classes.

so if A and B are classes, all you can (mostly) say is:
size(dex({A})) + size(dex({B})) >= size(dex({A, B}))
(in reality through, the use of larger indexes in bigger dex files might make that equation not hold.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants