Book Image

Swift High Performance

By : Kostiantyn Koval
Book Image

Swift High Performance

By: Kostiantyn Koval

Overview of this book

Swift is one of the most popular and powerful programming languages for building iOS and Mac OS applications, and continues to evolve with new features and capabilities. Swift is considered a replacement to Objective-C and has performance advantages over Objective-C and Python. Swift adopts safe programming patterns and adds modern features to make programming easier, more flexible, and more fun. Develop Swift and discover best practices that allow you to build solid applications and optimize their performance. First, a few of performance characteristics of Swift will be explained. You will implement new tools available in Swift, including Playgrounds and REPL. These will improve your code efficiency, enable you to analyse Swift code, and enhance performance. Next, the importance of building solid applications using multithreading concurrency and multi-core device architecture is covered, before moving on to best practices and techniques that you should utilize when building high performance applications, such as concurrency and lazy-loading. Finally, you will explore the underlying structure of Swift further, and learn how to disassemble and compile Swift code.
Table of Contents (15 chapters)
Swift High Performance
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Optimization checklist


Before doing any optimization and performance measurement, you should follow these steps:

  1. Enable the Release mode: The Swift compiler does a lot of code optimization and improves performance in the Release mode. To enable the Release mode go to Product | Scheme | Edit Scheme | Run, select the Info tab, and select Release in the Build Configuration setting.

  2. Disable safety checks: Disabling safety checks could improve application performance; but as its name suggests, it affects safety and disabling is not 100-percent safe and should be applied carefully. An example of a safety check Swift does is checking array bounds before accessing the memory. If you disable safety checks Swift won't do that.

    Disabling safety checks is a Swift Compiler – Code Generation setting that is available in the target Build Settings. To disable safety checks select Project | Build Settings, then search for the Disable Safety Checks setting and set it to Yes for the Release mode.

  3. Enable the Fast...