CocoaPods中,pod install
只會對.podfile
中,新的庫版本進行分析,並升級到podfile中的指定版本。
區別於pod install
,pod update
會到cocoaPods的倉庫地址中,去比對podfile
文件中,依賴的文件進行版本比對和按情況升級。
pod update
通常是比較耗時的操作,至於原因,本文會對CocoaPods在執行pod update
時的耗時影響做了簡單分析:
pod update
的5個步驟:
1. resolve_dependencies
* update repo(升級倉庫文件,下載至本地)
* 解析podfile
2. download_dependencies(下載podfile中的依賴及其間接依賴)
3. generate_pods_project(即生成dependency在Pods工程中的target,以及寫pod file.lock等文件)
4. integrate_targets
5. perform_post_install_actions
pod update
的幾個步驟,項目不同,耗時不同。
耗時分析
但針對幾個不同的步驟,其耗時狀況如下:
步驟 | 影響因素 | 耗時狀況 |
---|---|---|
resolve_dependencies | 輕量化操作,耗時很少 | 少 |
download_dependencies | 1. 有緩存明顯好於無緩存 2. 需要升級的依賴庫越耗時 | 多 |
generate_pods_project | 需要update的依賴庫越多越多,越耗時 | 較多 |
integrate_targets | 常規操作,耗時少,影響因素少 | 少 |
perform_post_install_actions | 常規操作,耗時少,影響因素少 | 少 |
當然耗時的很大的影響因素就是網絡狀況。
國內開發環境下,很多人用淘寶的鏡像就是這個原因,但可以翻牆的情況下,其影響較小。
結語
但坦白來說,pod update的耗時很大程度上取決於依賴庫的多少,所以開發者在選擇依賴庫時,擇優而取。