Conference paper Open Access

Optimization of Swift Protocols

Barik, Rajkishore; Sridharan, Manu; Ramanathan, Murali Krishna; Chabbi, Murali

Title: Optimization of Swift Protocols

Abstract:

Swift, an increasingly-popular programming language, advocates the use of protocols, which define a set of required methods and properties for conforming types.  Protocols are commonly used in Swift programs for abstracting away implementation details; e.g., in an industrial app, they are heavily used to enable mock objects for unit testing.  Unfortunately, heavy use of protocols can result in significant performance overhead.  Beyond the dynamic dispatch often associated with such a feature, Swift allows for both value and reference types to conform to a protocol, leading to significant boxing and unboxing overheads.

In this paper, we describe three new optimizations and transformations we have developed to reduce the overhead of Swift protocols.  Within a procedure, we define LocalVar, a data-flow analysis and transformation to remove both dynamic dispatch and boxing overheads.  We also describe Param, which optimizes the case of protocol-typed method parameters using specialization.  Finally, we describe SoleType, a transformation that injects casts when a global analysis (like type-hierarchy analysis) discovers some protocol variable must have some concrete type.  We also describe how these optimizations work fruitfully together and with existing Swift optimizations to deliver further speedups.

We perform elaborate experimentation and demonstrate that our optimizations deliver an average 1.56x speedup on a suite of Swift benchmarks that use protocols. Further, we applied the optimizations to a production iOS Swift application used by millions of customers daily. For a set of performance spans defined by the developers of the application, the optimized version showed speedups ranging from 6.9% to 55.49%. A version of our optimizations has been accepted as part of the official Swift compiler distribution.

Files (1.4 GB)
Name Size
benchmarks.tar.gz
md5:3413ddf24646f10ded189fe26f42afb8
13.0 kB Download
binary-swift-master-oopsla-submission.tar.gz
md5:85277307ed42d98760602bc6ef1ead54
109.9 MB Download
binary.tar.gz
md5:85277307ed42d98760602bc6ef1ead54
109.9 MB Download
README.md
md5:74dedf86c0dc255b8c1febe3c38e8fca
5.2 kB Download
sampleapp.tar.gz
md5:bafa7f271ab1ba462c9c78bfa1af6533
2.9 MB Download
swift-4.2-app-evaluation.tar.gz
md5:89ece72568fa79beae2b7523028fea62
15.7 MB Download
swift-master-08052019.tar.gz
md5:28a369e65291de02c54ccb81a112e105
502.9 MB Download
swift-master-oopsla-submission.tar.gz
md5:acd9f279060a99579665a28e2920030b
681.3 MB Download
185
128
views
downloads
All versions This version
Views 18557
Downloads 12830
Data volume 15.8 GB3.0 GB
Unique views 16855
Unique downloads 3210

Share

Cite as