When the iOS project is running, the XCode memory is skyrocketing, the speed is slow, and the solution process of the card

XCode old strike

Starting from this year, during the development process of the main project of a component in the project, it takes a long time to run and compile. Will XCode turn to chrysanthemum? The average compilation time is about 5 minutes each time, which greatly affects the development efficiency. I just finished the test today. , take the time to take a closer look at why it is so stuck.

  • environment
key value
Mac OS 13.2.1 (22D68)
Memory 16 GB
chip Apple M1
storage 512G
XCode 14.0.1
component code 19MB

Open the activity monitor when it is stuck, and find that XCode occupies a very high memory, with an average of about 20GB and a peak of 60GB

77611677480135_.pic.jpg

After Command + k deletes the cache in DerivedData, there is still no obvious acceleration result.

look for the reason

View compilation log

image.png

It is found that all files in the component will have several similar warnings when compiling.

These warnings come from the same file, referenced via the pch file.

The file with warnings is the network request file of the component, which was created a long time ago. There are NS_ASSUME_NONNULL_BEGINprobably hundreds of warnings in the file that are not automatically generated. When compiling files, these warnings will be cached and analyzed. Causes it to run very sluggish.

solve

Eliminate the warning, recompile, and find that the project runs very comfortably!

If there are warnings from other third-party libraries or components, you can add: to podFile inhibit_warnings => trueto avoid checking warnings during compilation. This approach also speeds up compilation.

pod 'XXNetEngineModule', :inhibit_warnings => true
复制代码

It can be seen that the memory size of XCode after solving is basically around 1GB. The compilation speed can basically reach second startup (within 10s).

image.png

Guess you like

Origin juejin.im/post/7207737667990945850