抖音 iOS 工程架構演進

{"type":"doc","content":[{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"前言介紹"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"2016.09.26,抖音版本 1.0.0 上線,隨後不斷迭代優化和豐富產品,截止目前,抖音日活躍用戶突破 6 億,短短 4 年間,抖音從零爆發性增長。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"快速的業務發展也對技術支撐提出了更高的要求,爲了保障敏捷的業務開發,提升跨團隊的協同合作效率,提高本地研發和 CI\/CD 效率,抖音 iOS App 工程架構在不同的階段進行了不同的技術方案的改進,滿足合理的架構演化,同時又不影響正常的業務迭代速度。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"抖音工程架構演進"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"架構演進的本質是爲了提高研發效率,提高代碼穩定性和保證代碼質量。架構要解決的問題是如何組織代碼。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"合理的架構設計可以解決大型項目跨團隊協作分工和多業務線並行開發的效率問題。抖音工程代碼從一開始就採用了組件化思路,依賴管理工具是定製版的 Cocoapods。"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"組件化"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在大型項目快速發展的過程中,要保證敏捷開發迭代的最大障礙就是快速膨脹的代碼體積導致的編譯效率問題,依賴關係複雜化問題,以及業務線代碼衝突問題。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"移動端項目可以類比後端項目中採用的微服務架構,要解決多業務線並行開發、並行測試問題,採用流水線式迭代開發,提高發版、集成、交付、提審、發佈效率,結合分治思想技術選型上可以採用組件化的方案。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"大部分小型項目,組件化僅僅做到代碼分倉,使用 Cocoapods 的來管理組件依賴,就像抖音項目最初的工程形態。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"但是對於幾百號人、幾十個業務線規模的大型項目,需要設計一套合理的組件分層架構,理清組件間依賴關係,需要 CI\/CD 工具鏈支撐組件發版與集成,需要本地研發工具支撐本地代碼同步、工程配置、依賴管理和效率優化。"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"流水線式迭代開發"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"流水線(pipeline)技術是指在程序執行時多條指令重疊進行操作的一種準並行實現技術,該技術可以充分提高資源的利用率,同時縮短產品的研發週期。對於客戶端項目,流水線技術能很大程度滿足敏捷開發迭代的節奏。"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/cc\/cc9242e396bd7c36400bae19b2ae990a.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"抖音流水線式迭代發版"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"抖音工程架構演進階段一:抖音原始工程架構(Original architecture of project)"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/b3\/b31d28297ddec6d98b47d176bd3e398a.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"抖音項目原始工程架構圖"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"抖音項目一開始是單體架構+Cocoapods,業務代碼、工程配置、資源文件全部放在一個大業務倉庫。由 Podfile 文件描述第三方倉庫的依賴版本。"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/28\/287d613a6e7e14e844079341d446fcd6.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"抖音項目原始工程架目錄結構"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"階段二:分離殼工程後的工程架構(After splitting of host shell pod)"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/4d\/4d7ed014fc75cb0c8b396f370d840ff5.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"拆分殼工程後的工程架構"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"分離殼工程後,工程配置、部分系統資源、工程主入口被拆分到主宿主殼工程。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Podfile 拆分出版本依賴管理文件 Podfile.seer,由依賴管理平臺進行各個版本的容器化管理,業務倉跟隨宿主集成發版,打平依賴,解決版本依賴決議耗時問題。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"大業務倉中的代碼和資源被拆分到各個業務線的倉庫下,由 podspec 文件描述內外依賴。業務線倉庫增加 ModuleInterface subspec,存放對外接口,採用依賴注入方式實現接口隔離,初步建立接口層。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"業務倉庫之間規定只能依賴其他業務倉庫的 ModuleInterface subspec,通過 lint 進行編譯檢查。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"部分基礎能力代碼被拆分成基礎倉庫,跟第三方倉庫一樣獨立發版。本地研發工具支持單倉開發和多倉開發,不參與代碼修改的倉庫通過二進制的方式進行鏈接。同時 CI 流程上也支持通過二進制打測試包,提高打包效率。"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/80\/802bddd72fb5491eff2f1548e5b13f02.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"抖音項目拆分殼工程後目錄結構"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"殼工程"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/55\/55fc206c328e559120b4da2090f705be.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"殼工程抽象"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"爲了滿足一個工程同時支持多個項目、部分業務線功能複用、部分業務線中臺化發展的需求,我們把所有業務線抽象成獨立的 Pod,所有業務 Pod 必須通過宿主的殼工程進行集成發版。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"殼工程包含了項目依賴的 Pod 信息描述,同時還包括工程的配置、部分系統級別的資源文件、工程主入口代碼。基於多份宿主殼工程,一份代碼可以打包出抖音、抖音極速版等項目。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"同時,基於宿主殼工程,一些業務線可以通過自動化同步生成自己的子殼工程,實現業務線自己的 Example 工程,進行獨立開發,比如有語音通話的 Example 工程,有工具的 Example 工程,有直播的 Example 工程等等。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/fd\/fd013aa102640fb6d19ddfa297d0a741.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"子殼工程配置同步同步"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"接口層"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"接口層顧名思義,只提供依賴的抽象接口,所有接口都是 protocol 協議聲明。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"接口層限制了所有其他依賴,類、枚舉、 外部協議都採用前向聲明,podspec 上只允許聲明對 DI(依賴注入)框架的依賴。接口層滿足封裝、隔離和組合的原則。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"業務層面對外封裝了實現代碼;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"編譯層面隔離了組件間依賴傳遞,減少頭文件 import 嵌套提高編譯緩存的命中率,對於 swift 業務組件,還能達到減少編譯傳遞的問題;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"架構層面聲明抽象協議支持接口組合;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"DI 容器框架同時支持 stateless DI 容器,也支持 stateful DI 容器。"}]}]}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"依賴打平"}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"採用 Cocoapods 本身自帶的版本依賴決議進行版本分析會消耗大量的時間;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Podfile.lock 過於繁瑣,可讀性很差,難以解決 Podfile.lock 的衝突;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"隱式依賴被動\/不符合預期地升級,難以確定性地聲明所有依賴,防止隱式依賴被升級;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"依賴版本在 Podfile\/Podfile.lock 重複聲明,增加了解決衝突的成本;"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Podfile.lock 參與依賴版本決議流程比較複雜,會出現不符合預期的情況。"}]}]}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/5b\/5b2ae1fc36f55db46e5fe9aae91f8263.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"把版本管理和倉庫源信息遷移到 Podfile.seer 文件"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"hook 掉 Cocoapods 採用 podfile.lock 進行版本決議的邏輯,採用 Podfile.seer 文件直接描述所有組件的版本信息,打平依賴。"}]}]}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"階段三:單倉多組件工程架構(Multicomponents in single repo)"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/0d\/0d86a113a2d7820f51c50a9c32524d6f.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"拆分單倉多組件後的工程架構"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"採用單倉多組件後,每個業務線倉庫支持添加 podspec 增加組件,實現更小粒度的二進制依賴。業務線倉庫內劃分業務實現層、業務接口層、服務層和基礎層,都是通過集成方式發版。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"新增的服務層主要存放公共的業務邏輯和通用服務,限制 UI,一是滿足業務邏輯複用,二是滿足子殼工程最小化二進制依賴。同時服務層的服務接口也達到隔離依賴傳遞的目的,在不同的宿主上,支持通過改變服務層實現替換後臺能力或者底層能力。建立分層間的依賴准入規則,完善 lint 編譯鏈接檢查。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/9a\/9a09b1f5fa1ff90a41c87fd2d7737f7f.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"單倉多組件目錄結構"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"編譯鏈接完備性校驗"}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"編譯校驗:分開編譯各個 subspec,確保每個 subspec 的依賴是正確的(由於 subspec 沒有編譯隔離)"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"接口符號校驗:校驗當前接口組件(ModuleInterface)中符號是否完備的,以保證其他組件單獨引用是否能正常使用。如 extern 聲明的全局變量。"}]}]}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"分層依賴准入規則:"}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"高層依賴低層"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"實現依賴接口"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"接口層無依賴"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"前向聲明優先"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"服務層去\"UI\""}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以下動畫展示了業務實現層和服務實現允許依賴的分層:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/85\/85245f2f68c82b0091802800c94b0c0d.gif","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"組件依賴關係示意圖動畫"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"階段四:Example 子殼工程架構(Subshell for bizcomponent in example project)"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/76\/763a3b11189979ce9f1bc82500cd3fa3.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"子殼工程架構"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"每個業務倉從宿主同步工程配置構建子殼工程。增加 AWELaunchKit 爲子殼工程提供運行時的基礎能力。通過服務層提供業務間運行時共享的服務能力,滿足代碼複用和更小二進制依賴。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/8e\/8e213078c5f2884da655f235214599af.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"子殼工程目錄結構"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"AWELaunchKit"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"AWELaunchKit 框架爲宿主和其他子殼工程提供了基礎服務的依賴和初始化配置。同時提供了一套啓動加載的 BootTasks 管理框架,部分業務涉及啓動相關的邏輯可以在業務倉對應的服務層中實現,並通過 BootTasks 管理框架註冊到啓動加載器裏面。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"同時框架還提供了一套宿主 UI 入口和自定義入口框架。爲了方便測試和調試,也整合了整套測試調試框架。"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/d6\/d65ca5ee4d322d5b09847cf566de62f5.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"子殼工程依賴關係"}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"組件化探索過程中遇到的一些問題:"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"二進制污染"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"組件之間的依賴除了顯式的依賴,還存在很多隱式依賴,代碼層面,除了普通的接口依賴,還有宏依賴、枚舉依賴、全局變量依賴以及內聯函數等的依賴。單倉 lint 進行編譯鏈接完備性檢查並不能解決依賴變動對其他二進制的影響。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"因此需要藉助源碼層面的依賴分析,判斷當前組件的變更對其他依賴當前組件的二進制是否有影響,在 CI 流程中及時發現並攔截。否則錯誤的二進制發版,會直接導致整個 CI 研發流程和本地研發都受到影響。"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"編譯優化"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"編譯優化最高效的方式就是提高緩存的利用率。對於本地研發和 CI 流程,都涉及分佈式編譯緩存同步。同時通過編譯參數優化、依賴優化、hmap 優化也能不同程度的提高編譯效率"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"主幹分支穩定性問題"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"對於多業務線並行開發,幾百號人的業務開發團隊,如果主幹分支一旦出現問題,那麼解決問題的時間就需要乘上幾百倍。因此,需要從編譯層面和運行層面都要有足夠的機制去保證一個穩定的主幹分支,才能保證業務側的長期穩定性。"}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"業務層的依賴耦合問題"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"大型項目動則千萬行的代碼,代碼間的依賴關係是複雜的網狀關係。需要基於代碼的語法樹模型,從語義中去分析不合理的依賴,並輸出治理的方案。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我們內部自研了源碼依賴關係分析平臺用於依賴關係分析監控和代碼治理,長期監控組件間的依賴度。同時,需要建立依賴健康度模型,從長期演進的角度去監控防止代碼的劣化。"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/46\/462d2da01e387f0f375d0ae388b5a083.png","alt":"圖片","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"spider 組件依賴分析平臺"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"總結"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"大型項目的組件化工作是一個系統性工程。涉及工程架構的改造、CI\/CD 研發工具鏈的支撐、本地研發工具鏈的支撐,業務架構的設計優化,需要從各個方面綜合考慮成本和收益。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"沒有最好的架構,只有更好的架構,在架構演進的過程中,我們需要充分考慮架構的改動對業務的影響以及能給業務帶來的收益。好的架構一定是能幫助業務節省時間,保證質量的。與此同時,我們在架構改進的過程中,要保證不能影響業務的正常迭代,所以向前兼容且避免大面積衝突也是很重要的事情。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"組件化裏面處處都有驚喜,比如一個小小的 hmap 優化,可以很大程度的減少編譯耗時,比如一個二進制的壓縮和解壓的優化,可以很大程度減少 pod install 的整體耗時。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"當然這裏面也會有很多很棘手的問題,需要通過一些特殊的方案解決,比如針對分佈式開發,由於阻塞式發版必然會導致一些不同分支存在衝突的代碼發版後影響主幹的穩定性。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"本文轉載自:字節跳動技術團隊(ID:toutiaotechblog)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"原文鏈接:"},{"type":"link","attrs":{"href":"https:\/\/mp.weixin.qq.com\/s\/HHH5_IEbsR8iSmXSIdeutw","title":"xxx","type":null},"content":[{"type":"text","text":"抖音 iOS 工程架構演進"}]}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章