Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Limited import clarification and its effect/tryswift2019

Limited import clarification and its effect/tryswift2019

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.

noppefoxwolf

March 21, 2019
Tweet

More Decks by noppefoxwolf

Other Decks in Programming

Transcript

  1. Limited import clarification
    and its effect
    try! Swift Tokyo 2019
    Tomoya Hirano @DeNA

    View Slide

  2. Import

    View Slide

  3. Import Declaration
    1. attributes import module
    2. attributes import module.submodule
    3. attributes import importKind module.symbolName

    View Slide

  4. Import Declaration
    1. attributes import module
    2. attributes import module.submodule
    3. attributes import importKind module.symbolName

    View Slide

  5. 1. Attributes
    • Specify how to import symbols

    • Optional

    • @testable / @_exported

    View Slide

  6. @testable
    • For testing and development.

    • Import internal methods as public.

    View Slide

  7. @_exported
    • Import symbols as own code

    • Undocumented attributes

    View Slide

  8. 2. Submodule import
    1. attributes import module
    2. attributes import module.submodule
    3. attributes import importKind module.symbolName

    View Slide

  9. Example: SceneKit initializer

    View Slide

  10. Example: SceneKit initializer

    View Slide

  11. 3. Kind import
    1. attributes import module
    2. attributes import module.submodule
    3. attributes import importKind module.symbolName

    View Slide

  12. struct class enum protocol
    typealias func let var
    3. Kind import

    View Slide

  13. 3. Kind import
    • Individual import is only top-level

    • Cannot import overloaded functions separately

    View Slide

  14. Example: Conflict method name

    View Slide

  15. View Slide

  16. 1. Attributes

    2. Submodule import

    3. Kind import
    Import Options

    View Slide

  17. Can the build time be shortened?

    View Slide

  18. 4. Measuring the build times
    • made 100,000 methods

    • import Core vs import func Core.function0

    • Tried 10 times

    View Slide

  19. Basic Import Kind Import
    Average 277.645s 285.105s(+7.64s)
    Max 309.46s 312.99s(+3.53s)
    Min 273.48s 265.25s(-8.23s)
    Build time

    View Slide

  20. Basic Import Kind Import
    Filesize 7336KB 7336KB
    Md5
    0b10a59ce0a75decbb
    2f120520c4fbc1
    0b10a59ce0a75decbb
    2f120520c4fbc1
    Binary size

    View Slide

  21. Build time Binary Size Namespace
    Simple Import Same Same Optional
    Kind specify Same Same Necessary
    Pros & Cons

    View Slide