Import is able to explicitly specify submodules or specific elements.In this session, I will review the specifications of these imports and consider the impact on binary size and performance.
Limited import clarificationand its effecttry! Swift Tokyo 2019Tomoya Hirano @DeNA
View Slide
Import
Import Declaration1. attributes import module2. attributes import module.submodule3. attributes import importKind module.symbolName
1. Attributes• Specify how to import symbols• Optional• @testable / @_exported
@testable• For testing and development.• Import internal methods as public.
@_exported• Import symbols as own code• Undocumented attributes
2. Submodule import1. attributes import module2. attributes import module.submodule3. attributes import importKind module.symbolName
Example: SceneKit initializer
3. Kind import1. attributes import module2. attributes import module.submodule3. attributes import importKind module.symbolName
struct class enum protocoltypealias func let var3. Kind import
3. Kind import• Individual import is only top-level• Cannot import overloaded functions separately
Example: Conflict method name
1. Attributes2. Submodule import3. Kind importImport Options
Can the build time be shortened?
4. Measuring the build times• made 100,000 methods• import Core vs import func Core.function0• Tried 10 times
Basic Import Kind ImportAverage 277.645s 285.105s(+7.64s)Max 309.46s 312.99s(+3.53s)Min 273.48s 265.25s(-8.23s)Build time
Basic Import Kind ImportFilesize 7336KB 7336KBMd50b10a59ce0a75decbb2f120520c4fbc10b10a59ce0a75decbb2f120520c4fbc1Binary size
Build time Binary Size NamespaceSimple Import Same Same OptionalKind specify Same Same NecessaryPros & Cons