Swift性能優化分析

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"自從2014年Apple發佈Swift語言以來,歷時六年多,Swift已經發布到5.3版本,在5.0版本已經ABI stability,5.2版本也已經module stability,不管是語言還是基礎庫都日趨穩定,目前國內外大廠也都積極擁抱Swift陣營。","attrs":{}}]},{"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":"絕大多數公司選擇Swift語言開發iOS應用,主要原因是因爲Swift相比Objc有更快的運行效率,更加安全的類型檢測,更多現代語言的特性提升開發效率;這一系列的優點使Swift語言的熱度越來越高。","attrs":{}}]},{"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":"大多數人知道Swift語言相比於Objc語言運行效率更高,但是卻不知道爲什麼效率更高,在這裏我們Swift編譯層探討一下Swift語言高效的原因。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"更加高效的數據類型","attrs":{}}]},{"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":"在開始討論Swift數據類型之前,我們先討論一下Swift的函數派發機制;","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"靜態派發、動態派發、消息派發(static dispatch、dynamic dispatch、message dispatch)","attrs":{}}]},{"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":"動態派發(dynamic dispatch): 動態派發是指編譯期無法確定應該調用哪個方法,需要在運行時才能確定方法的調用。","attrs":{}}]},{"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":"靜態派發(static dispatch):是在編譯期就能確定的調用方法的派發方式。","attrs":{}}]},{"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":"除了上面兩種方式之外,在Swift裏面還會使用Objc的消息派發(message dispatch))機制;Objc採用了運行時採用","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"obj_msgsend","attrs":{}}],"attrs":{}},{"type":"text","text":"進行消息派發,所以Objc的一些動態特性在Swift裏面也可以被限制的使用。","attrs":{}}]},{"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":"靜態派發相比於動態派發更快,而且靜態派發還會進行內聯等一些優化,減少函數的尋址及內存地址的偏移計算等一系列操作,使函數的執行速度更快,性能更高。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"數據類型(struct/class)","attrs":{}}]},{"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":"我們都知道,內存分配可以分爲堆區(Heap)和棧區(Stack)。由於棧區內存是連續的,內存的分配和銷燬是通過入棧和出棧操作進行的,速度要高於堆區。堆區存儲高級數據類型,在數據初始化時,查找沒有使用的內存,銷燬時再從內存中清除,所以堆區的數據存儲不一定是連續的。","attrs":{}}]},{"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":"類(class)和結構體(struct)在內存分配上是不同的,基本數據類型和結構體默認分配在棧區,而像類這種高級數據類型存儲在堆區,且堆區數據存儲不是線程安全的,在頻繁的數據讀寫操作時,要進行加鎖操作。","attrs":{}}]},{"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":"我們在swift文檔裏面能看到對結構的描述,結構體是值類型(Value Type),當值類型的數據賦值給一個變量或常量,或者傳遞給一個函數時,是值拷貝;","attrs":{}}]},{"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":"例如:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"struct Resolution {\n var width = 0\n var height = 0\n}\n\nlet hd = Resolution(width: 1920, height: 1080)\nvar cinema = hd\ncinema.width = 2048\n\nprint(\"cinema is now \\(cinema.width) pixels wide\")\n// Prints \"cinema is now 2048 pixels wide\"\n\nprint(\"hd is still \\(hd.width) pixels wide\")\n// Prints \"hd is still 1920 pixels wide\"\n","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"通過這個例子我們能清楚的看到,當","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"hd","attrs":{}}],"attrs":{}},{"type":"text","text":"賦值給","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"cinema","attrs":{}}],"attrs":{}},{"type":"text","text":"時,是將","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"hd","attrs":{}}],"attrs":{}},{"type":"text","text":"中存儲的值拷貝給","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"cinema","attrs":{}}],"attrs":{}},{"type":"text","text":",所以當給","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"cinema","attrs":{}}],"attrs":{}},{"type":"text","text":"的","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"width","attrs":{}}],"attrs":{}},{"type":"text","text":"屬性賦值的時候,並不會改變","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"hd","attrs":{}}],"attrs":{}},{"type":"text","text":"中的屬性值,如下圖所示:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/3e/3e1791647b891f0003e136893c087aea.png","alt":null,"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":null,"origin":null},"content":[{"type":"text","text":"image","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"結構體除了屬性的存儲更安全、效率更高之外,其函數的派發也更高效。由於結構體不能被繼承,也就是結構體的類型被","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"final","attrs":{}}],"attrs":{}},{"type":"text","text":"修飾,根據我們對於動態派發及靜態派發的描述,那麼其內部函數應該是屬於靜態派發,在編譯期就確定了函數的執行方式,其函數的調用通過內聯(inline)的方式進行優化,其內存連續,減少了函數的尋址及內存地址的偏移計算,其運行相比於動態派發更加高效。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"協議類型(protocol type)","attrs":{}}]},{"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":"多態是面向對象的一大特性,在結構體中不能通過繼承或者引用語言的多態,swift就引入了協議(protocol),通過協議來實現了結構體的多態特性,這也是swift面向協議編程的核心所在。","attrs":{}}]},{"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":"對於類(class)來說,每個類都會創建一個虛擬函數表指針,這個指針則指向一個v-table表,也就是虛函數表,表內存儲着該類的函數指針數組,擁有繼承關係的子類會在虛函數表內通過繼承順序(C++可以實現多繼承)去展示虛函數表指針。類裏面方法的派發則是根據v-table表裏面函數指針來進行派發。","attrs":{}}]},{"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":"而結構體(struct)沒有繼承,也就是說結構體並沒有v-table表用於函數的派發。爲了實現這一特性,在結構體的協議(protocol)的實現裏添加了Protocol Witness Table用於管理協議類型的方法派發。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"編譯過程","attrs":{}}]},{"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":"上面介紹了一些swift在數據結構上的一些優化,除了數據結構優化之外,swift在編譯過程也進行了大量的優化,其中最核心的優化,是在編譯過程中引入","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"SIL","attrs":{}}],"attrs":{}},{"type":"text","text":"。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"SIL","attrs":{}}],"attrs":{}},{"type":"text","text":",Swift Intermediate Language,是爲了優化swift編譯過程而設計的中間語言,主要包含了以下功能:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"numberedlist","attrs":{"start":null,"normalizeStart":1},"content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"一系列的高級別優化保障,用於對運行時和診斷行爲提供可預測的基線;","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"對swift語言數據流分析強制要求,對不滿足強制要求的問題產生診斷。例如變量和結構體必須明確初始化,代碼可達性即方法return的檢測,switch的覆蓋率;","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":"確保高級別優化。包含retain/release優化,動態方法的去虛擬化,閉包內聯,內存初始化提升和泛型方法實例 化.","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":4,"align":null,"origin":null},"content":[{"type":"text","text":"可用於分配\"脆弱\"內聯的穩定分配格式,將Swift庫組件的泛型優化爲二進制。","attrs":{}}]}],"attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"Clang編譯流程","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/a7/a7ea03f07cb44116cfc33a5558d6d6b9.png","alt":null,"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":null,"origin":null},"content":[{"type":"text","text":"image","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Clang編譯過程有以下幾個缺點:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"numberedlist","attrs":{"start":null,"normalizeStart":1},"content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"與代碼與LLVM IR之間有巨大的抽象鴻溝(Wide abstraction gap between source and LLVM IR );","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"IR不適合源碼級別的分析(IR isn't suitable for source-level analysis );","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":"CFG(Control Flow Graph)缺少精準度(CFG lacks fidelity );","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":4,"align":null,"origin":null},"content":[{"type":"text","text":"CFG偏離主道(CFG is off the hot path );","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":5,"align":null,"origin":null},"content":[{"type":"text","text":"在CFG和IR降級中會出現重複分析(Duplicated effort in CFG and IR lowering)。","attrs":{}}]}],"attrs":{}}]},{"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":"由於以上這些缺點,swift語言開發團隊在開發過程中進行了一系列的優化,其中最關鍵的是引入","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"SIL","attrs":{}}],"attrs":{}},{"type":"text","text":".","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"swift編譯流程","attrs":{}}]},{"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":"Swift作爲一個高級別和安全的語言具有以下特點:","attrs":{}}]},{"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","marks":[{"type":"strong","attrs":{}}],"text":"高級別語言","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"通過代碼充分的展示語言的特性(Move more of the language into code)","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"支持基於協議的泛型(Protocol-based generics)","attrs":{}}]}],"attrs":{}}],"attrs":{}},{"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","marks":[{"type":"strong","attrs":{}}],"text":"安全語言","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"充分的數據流檢查:未初始化變量,函數返回處理檢測,這些項在檢測不合格時會產生對應的編譯錯誤(Uninitialized vars, unreachable code should be compiler errors)","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"邊界和溢出的檢測(Bounds and overflflow checks)","attrs":{}}]}],"attrs":{}}],"attrs":{}},{"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":"swift編譯流程:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/f4/f45f8a8fd4cb31afdb0df687c0c398e0.png","alt":null,"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":null,"origin":null},"content":[{"type":"text","text":"image","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Swift 源碼到IR之間的流程:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/b9/b984c20ce00ab428c6554e717b1ec837.png","alt":null,"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":null,"origin":null},"content":[{"type":"text","text":"image","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Swift 編譯過程引入","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"SIL","attrs":{}}],"attrs":{}},{"type":"text","text":"有幾個優點:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"numberedlist","attrs":{"start":null,"normalizeStart":1},"content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"完成的變數程序的語義(Fully represents program semantics );","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"既能進行代碼的生成,又能進行代碼分析(Designed for both code generation and analysis );","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":"處在編譯管線的主通道(Sits on the hot path of the compiler pipeline );","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":4,"align":null,"origin":null},"content":[{"type":"text","text":"架起橋樑連接源碼與LLVM,減少源碼與LLVM之間的抽象鴻溝(Bridges the abstraction gap between source and LLVM)","attrs":{}}]}],"attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"Swift編譯器的流程","attrs":{}}]},{"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":"Swift編譯器作爲高級編譯器,具有以下嚴格的傳遞流程結構。","attrs":{}}]},{"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":"Swift編譯器的流程如下:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Parse: 語法分析組件從Swift源碼構成AST","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"語義分析組件對AST進行類型檢查,並對其進行類型信息註釋。","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"SILGen組件從AST形成\"原始(raw)\"SIL","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"一系列在 ","attrs":{}},{"type":"text","marks":[{"type":"italic","attrs":{}}],"text":"生","attrs":{}},{"type":"text","text":" SIL上運行的,用於確定優化和診斷合格,對不合格的代碼嵌入特定的語言診斷。這些操作一定會執行,即使在","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"-Onone","attrs":{}}],"attrs":{}},{"type":"text","text":"選項下也不例外。之後產生 ","attrs":{}},{"type":"text","marks":[{"type":"italic","attrs":{}}],"text":"正式(canonical)","attrs":{}},{"type":"text","text":" SIL.","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"一般情況下,是否在正式","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"SIL","attrs":{}}],"attrs":{}},{"type":"text","text":"上運行","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"SIL","attrs":{}}],"attrs":{}},{"type":"text","text":"優化是可選的,這個檢測可以提升結果可執行文件的性能.可以通過優化級別來控制,在","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"-Onone","attrs":{}}],"attrs":{}},{"type":"text","text":"模式下不會執行.","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"IRGen會將","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"正式SIL","attrs":{}}],"attrs":{}},{"type":"text","text":"降級爲LLVM IR.","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"LLVM後端提供LLVM優化,執行LLVM代碼生成器併產生二進制碼.","attrs":{}}]}],"attrs":{}}],"attrs":{}},{"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":"在上面的流程中,","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"SIL","attrs":{}}],"attrs":{}},{"type":"text","text":"對Swift的編譯過程進行了一系列的優化,即保證的代碼執行的安全性,又提升了代碼執行的效率.","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"結尾","attrs":{}}]},{"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":"上面從Swift語言設計的數據結構及編譯流程等方面進行了簡單的分析,中間有很多細節沒有在文章裏闡述特別清晰,如果有興趣瞭解更多,可以參考以下資料。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":1},"content":[{"type":"text","text":"推薦文章","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://www.jianshu.com/p/5f5642d84262","title":null},"content":[{"type":"text","text":"Swift學習筆記","attrs":{}}]}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://www.jianshu.com/p/780741051da2","title":null},"content":[{"type":"text","text":"Swift學習總結","attrs":{}}]}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://www.jianshu.com/p/cd2911b6ae65","title":null},"content":[{"type":"text","text":"【Swift實現代碼】iOS架構模式之MVP","attrs":{}}]}]}],"attrs":{}}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://links.jianshu.com/go?to=https%3A%2F%2Fjuejin.cn%2Fpost%2F6887862144126484493","title":null},"content":[{"type":"text","text":"查看原文","attrs":{}}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章