ProGuard (which, for example, comes with an Android SDK to reduce code size), you can do all kinds of manipulations to compress JAR files
- Calculate constant expressions.
- Remove unnecessary field calls and method calls.
- Delete unnecessary branches.
- Remove unnecessary comparisons and test instances.
- Remove unused code blocks.
- Merge identical code blocks.
- Reduce the selection of variables.
- Delete write-only fields and unused method parameters.
- Internal constant fields, method parameters, and return values.
- Built-in methods, short or only called once.
- Simplification of tail recursion calls.
- Combine classes and interfaces.
- Make methods private, static, and final when possible.
- Make classes static and final whenever possible.
- Replace interfaces with single implementations.
- Perform over 200 optimizations in the form of bitmaps, such as replacing ... * 2 with ... <1.
- It is not necessary to delete the registration code.
They do not mention deleting debugging information in this list, but I think they can do it as well.
Update: Yes, indeed:
By default, the compiled bytecode still contains a lot of debugging information: source file names, line numbers, field names, method names, argument names, variable names, etc. This information makes it easy to decompile bytecode and reverse entire programs. This is sometimes undesirable. Obfuscators such as ProGuard can remove debugging information and replace all names with meaningless sequences of characters, which greatly complicates the process of code conversion. It further compresses the code as a bonus. The program remains functionally equivalent, with the exception of class names, method names, and line numbers specified in the exception stack trace.
source share