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 full-size slide

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

    View full-size slide

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

    View full-size slide

  4. 1. Attributes
    • Specify how to import symbols

    • Optional

    • @testable / @_exported

    View full-size slide

  5. @testable
    • For testing and development.

    • Import internal methods as public.

    View full-size slide

  6. @_exported
    • Import symbols as own code

    • Undocumented attributes

    View full-size slide

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

    View full-size slide

  8. Example: SceneKit initializer

    View full-size slide

  9. Example: SceneKit initializer

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    • Cannot import overloaded functions separately

    View full-size slide

  13. Example: Conflict method name

    View full-size slide

  14. 1. Attributes

    2. Submodule import

    3. Kind import
    Import Options

    View full-size slide

  15. Can the build time be shortened?

    View full-size slide

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

    • import Core vs import func Core.function0

    • Tried 10 times

    View full-size slide

  17. 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 full-size slide

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

    View full-size slide

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

    View full-size slide