Practice report on reducing the volume of ipa package

Practice report on reducing the volume of ipa package

  • foreword

From the user's point of view, I don't like apps that take up too much memory. First of all, if the user downloads it using traffic, the size of the ipa installation package will affect whether the user decides to download the app, even if it is successfully installed, because If the ipa installation package is too large, the download time will inevitably be prolonged, and the installation may be canceled midway. Even if the installation is completed successfully, not every user's mobile phone has a large memory configuration. When the memory is insufficient, the larger APP will be deleted. The greater the possibility of deletion, and the larger the app, the redundant code and discarded resources will increase the cost of learning and maintenance to a certain extent as the version is iterated.

So the size of the installation package is very important for the product.

 

  • Before the implementation of the program

Take the decompressed data of the independent APP as an example (101,210,812 bytes (108.1 MB on the disk), the actual size of ipa: 56,741,732 bytes (56.7 MB on the disk)):

  1. Executable, 76,895,552 bytes (76.9 MB on disk), or 75.97563% of the ipa package (43,109,888.3 bytes, 43.0781822 MB)
  2. Image, 21,299,483 bytes (27.6 MB on disk), or 21.044672% of the ipa package (11,941,111.3 bytes, 11.932329 MB)
  3. Other files, 3,015,777 bytes (3.6 MB on disk), or 2.979698% of the ipa installation package (1,690,732.25 bytes, 1.68948877 MB)

 

 

Unzip the package

Ipa

percentage

total size

108.1 MB

56.7 MB

--

executable file

76.9 MB

43.0781822 MB

75.97563%

picture

27.6 MB

11.932329 MB

21.044672%

other

3.6 MB

1.68948877 MB

2.979698%

 

    The data is transformed into a pie chart as follows:

 

From the above data analysis, it can be concluded that the largest proportion of the size of the ipa installation package is monopolized by executable files, followed by image resources, and other types of files can be ignored. Combined with practical problems, give the ipa installation package To lose weight, the methods adopted range from easy to difficult. I think we can start from the following aspects:

  1. Clean up useless, duplicate images.
  2. Remove obsolete code, including class files, function methods.
  3. To further compress the image resources in use, use compression tools to perform lossy or lossless compression, which can effectively reduce the volume of ipa in theory.

 

  • The effect after processing

1. Executable file, 73,608,704 bytes (73.6 MB on disk), reduced by 3.3 MB after optimization, and executable file of ipa occupies about 40 MB, reduced by 2.8110983 MB after optimization

2. Image files, 19,409,138 bytes (24.8 MB on the disk), reduced by 2.8 MB after optimization, ipa image files accounted for about 11.2 MB, reduced by 0.7786528 MB after optimization

3. Other files, 23,030,879 bytes (2.6 MB on disk), reduced by 1 MB after optimization, other files of ipa accounted for about 1.6 MB, reduced by 0.1102488 MB after optimization

 

Standalone APP uncompressed size (95,048,721 bytes (101 MB on disk)), reduced by 6,162,091 bytes (7.1 MB), ipa size 53,035,471 bytes (53 MB on disk), reduced by 3,706,261 bytes (3.7 MB)

 

result:

 

Unzip package reduction

Final Ipa reduction

ipa optimization

executable file

3.3 MB

2.8110983 MB

--

picture file

2.8 MB

0.7786528 MB

--

Other files

1 MB

0.1102488 MB

--

total size

7.1 MB

3.7 MB

6.525573%

 

 

  • Related tools and knowledge introduction

Project development will introduce a large number of resources such as pictures and codes as time goes on and more functional modules are added. However, during development, developers forget to remove related resources when deleting some functions, because the source code and resources are separated, and over time, there will be a large number of redundant resource images in the project. Similarly, in the iterative work, a large amount of logic code will continue to be generated, but not all logic codes are valid, and a small part is redundant, or originally useful, but gradually lost in frequent iterative updates A practical value has been lost, but it has not been cleaned up.

Image resources are relatively easy to find. The specific method is nothing more than searching and searching one by one. If Xcode cannot search, it means that they are no longer used. The method of searching for class file functions is the same, but the efficiency of searching is too low, and it is also very likely. error.

Why do you say it is possible? Because in the code, it is possible to complete the logic by splicing parameters, and this situation cannot be found through matching.

Therefore, we need tools: to quickly find redundant resource code files.

 

executable file

     Here we need to use two tools otool and linkmap

  1. Find useless class class.

Due to the dynamic nature of OC, no matter whether it is used or not, the compiler will compile all classes into executable files. In order to find out these redundant classes, we used the otool tool for reverse engineering checks.

Step1: Find all classes

      otool -v -s __DATA __objc_classlist executable path

Step2: Find the class in use

      otool -v -s __DATA __objc_classrefs executable path

Step3: The subtraction of two sets is a useless class.

  1. Find useless function method selectors.

Step1: Find all the function methods

      There are two methods:

      linkMap: __TEXT.__text of the LinkMap file, through the regular expression ([+|-][.+\s(.+)]), we can extract all objc class methods and instance methods in the current executable file.

      Otool:

      a:otool -oV executable file path

     

      b: Match each line of the content of a through regularization (\s*imp 0x\w+ ([+|-]\[.+\s(.+)\])), and the final set is all objc in the current executable file Class methods and instance methods .

 

picture

LSUnusedResources

    This is a tool to find useless pictures of projects

 

 

This tool can find a large number of unused pictures in the project, but it is not guaranteed to be accurate, but if the found pictures are not given, it can basically be guaranteed to have been used, so it still has great reference value.

 

Gemini 2

This is a file checking tool that can quickly help you find duplicate file content in the Mac hard drive and clean it up.

 

ImageOptim

It is an image compression software for Mac operating system .

 

     ImageOptim is absolutely a must-have image compression tool in front-end development, especially for the processing of images such as PNG, JPEP, and GIF . The software directly integrates the functions of many famous image processing tools on Win and Linux . Featured functions, such as: PNGOUT, AdvPNG, Pngcrush, OptiPNG, JpegOptim, Gifsicle , etc.

 

  • Stone from Other Hills
  1. Support BitCode, BitCode is an intermediate code technology solution unique to Apple, because the old version of the project is usually compatible with devices with different instruction sets when compiling and packaging, and usually packs all instruction sets into one installation package. As a result, the size of the installation package increased for no reason, so Apple launched a technical solution called BitCode, which combines the same parts to form an intermediate code, so that different instruction sets can run.
  2. The picture resource adopts the vector pdf file, and the pdf file can be zoomed in and out, and the volume is smaller, which can adapt to the needs of various models.
  3. The pictures are unified and synthesized into a large picture, and different coordinate positions are used to read the picture, which is modeled on the resource management method of mobile games.
  4. Infrequently used resources are changed to online downloading.

Guess you like

Origin blog.csdn.net/harder321/article/details/85244111