facebook / redex

A bytecode optimizer for Android apps
https://fbredex.com/
MIT License
6.03k stars 653 forks source link

Redex increasing apk size #639

Open kamalgsharma opened 3 years ago

kamalgsharma commented 3 years ago

Hi,

I am running redex on an empty config and it appears that Redex increases the size of the apk signficantly ~2MB. The changes are in the dexes. From my initial analysis, it appears that the changes due to the goto movement, but there might be some other issue as well. Details can be found in the repro instructions.

I have placed the dex before/after here for easy analysis.

Questions:

  1. What causes the size increase? Is there a flag that I am missing here.
  2. Is there any optimization affecting the dexes. I have not enabled anything by default in the config and the debug/trace output also doesn't show anything.

Thanks in advance.

Repro instructions: Download a copy of the apk here: https://droidbang.com/link/airbnb-android ver 21.35 Make changes to redex code by adding dex version 37 and disabling the verifier. Command used: redex.py -c empty.config --android-sdk-path=/Users/kamal_sharma/Library/Android/sdk -o output.apk com.airbnb.android_21.35_24003757.apk --log-level debug

empty.config : { "redex" : { "passes" : [ ] } }

kamalgsharma commented 3 years ago

So, I could resolve the issue on my own by adding the following to config. "debug_info_kind": "no_custom_symbolication", "method_move_map" : "redex-moved-methods-map.txt", "string_sort_mode" : "class_order", "bytecode_sort_mode" : ["method_similarity_order", "class_order"], "ir_type_checker": { "run_after_each_pass" : false, "verify_moves" : false

kamalgsharma commented 3 years ago

Reopening the issue, the dexes are still larger. Some metadata was removed, but dexes are still larger with this config as well.

NTillmann commented 3 years ago

Make changes to redex code by adding dex version 37 and disabling the verifier.

Redex doesn't support DEX 37. In fact, I just landed a change that adds a additional verification. Just ignoring the issues can very well lead to unintended subtle semantic changes that you don't want.

Anyway.

To get an idea what's going on with your side increase, can you post a link to your "redex-stats.txt" file?

kamalgsharma commented 3 years ago

@NTillmann , I saw in the code that it has dex version for 37. It also builds fine. Also, will we have that support in the future?

NTillmann commented 3 years ago

We don't have plans to support version 37. We investigated, but didn't find that going beyond 35 would provide meaningful benefits, considering both runtime performance and code size.

kamalgsharma commented 3 years ago

redex-stats.txt default.config.txt @NTillmann , attached is the stats and default.config.