Slide 1

Slide 1 text

HOW SWIFT IS SWIFT? @jl_hfl

Slide 2

Slide 2 text

SWIFT IS DESIGNED FOR SPEED Static Typing Value Types No pointer aliasing* Constants Copy on write @jl_hfl

Slide 3

Slide 3 text

WHAT TO OPTIMISE Blocking I/O, Network efficiency, Library calls, Algorithmic complexity, Data structures. Build settings Profile and Measure Optimise General Code Metal/Accelerate/OpenGL/Parallelism @jl_hfl

Slide 4

Slide 4 text

BUILD SETTINGS -Onone -O -Ounchecked SWIFT_WHOLE_MODULE_OPTIMIZATION @jl_hfl

Slide 5

Slide 5 text

See video of build settings. And also the effect of using a class instead of a struct @jl_hfl

Slide 6

Slide 6 text

Debug (15 and 32 minutes) @jl_hfl

Slide 7

Slide 7 text

MAKE TWO TARGETS ▸ Development - critical parts in Framework ▸ Release - all optimised, monolithic build. Test the Release builds Use C/C++ if really needed for core inner loop @jl_hfl

Slide 8

Slide 8 text

IS SWIFT FASTER THAN OBJECTIVE C? IT DEPENDS @jl_hfl

Slide 9

Slide 9 text

HOW FAST IS SWIFT Within 20% of C/C++ version is usually possible. Geekbench - FFT and Mandelbrot Swift matches C++ but GEMM was 4 x faster in C++. David Owens - Gradient render 7 times faster in C (-Ofast). @jl_hfl

Slide 10

Slide 10 text

SIMPLE OPTIMISATIONS struct final let ContiguousArray inout DANGEROUS OPTIMISATIONS &+ &- &* Unmanaged @jl_hfl

Slide 11

Slide 11 text

SLOW THIS ONLY MATTERS IN THE REAL CODE HOTSPOTS ▸ Global/class/static var (let is fine) ▸ Function calls that can't be inlined ▸ Access via protocol or to non-final class methods/properties ▸ @objc or NSObject @jl_hfl

Slide 12

Slide 12 text

CHECKLIST 1. Build settings 2. Profile 3. Measure 4. Structs 5. Final @jl_hfl

Slide 13

Slide 13 text

Links/Credits Primatelabs (Geekbench) - http://www.primatelabs.com/blog/ 2015/02/swift-performance-updated David Owens - http://owensd.io/2015/02/24/swift-1_2-beta-2.html My blog has several performance related posts: http://blog.human- friendly.com/ I'm @jl_hfl on Twitter. Thanks to Simon Gladman for the original Cellular Automata code. @jl_hfl