Does #import <UIKit/UIKit.h> on pch slow down the compile time?

那年仲夏 提交于 2019-12-06 02:56:05

问题


I was reading this post about imports and I had one question. Does the #import that comes in the prefix.pch file by default slow down the compile time? Should I remove it and import only when necessary?

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
#endif

回答1:


No. It actually improves the compilation speed.

This is a nice tutorial that actually clears all the confusion over use of #import statements and .PCH files. Also it tells you in detail about something new known as "modules", introduced in iOS7.




回答2:


Since Xcode 5, there is a new feature introducing precompiled sources database. Xcode 5 basically compiles all the required frameworks just once, saves builds in the database and that already compiled pieces uses while compiling your code. So nothing in the library is not compiled multiple times.

So my guess is, while using Xcode 5, you don't need to worry.

You can watch WWDC 2013 video "What’s New in Xcode 5" introducing this feature at https://developer.apple.com/wwdc/videos/

If I'm wrong, please anyone more informed, feel free to correct me.




回答3:


This may sound controversial, but contrary to what everyone is saying about modules, I've had the complete opposite experience. I've got, what you'd consider, a large project (considerably large with various dependencies and libraries). Recently I started noticing that compile times were very very very long (around 5 minutes normal build time and around 15 minutes 'archive' time on a 2014 Mac Pro 12 cores and 32 GB RAM).

I ran an experiment by simply turning off Enable Link Frameworks Automatically on all libraries and projects as well as Enable Modules. I 'archived' and it took 3 minutes archive.

I turned 'Enable Modules' ON and did the same, and it took, as normal, 15 minutes. Strange and weird, but I'm sticking with these options turned off.



来源:https://stackoverflow.com/questions/19030521/does-import-uikit-uikit-h-on-pch-slow-down-the-compile-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!