There is a newer version of this record available.

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.3 GB)
Name Size
benchmarks.tar.gz
md5:3413ddf24646f10ded189fe26f42afb8
13.0 kB Download
binary.tar.gz
md5:85277307ed42d98760602bc6ef1ead54
109.9 MB Download
README.md
md5:c7f31e37b6fc266cae3f23c65186f47b
3.5 kB Download
README_BENCHMARK.md
md5:82b33342209bf37e3dd25b54478acc6e
1.4 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
102
110
views
downloads
All versions This version
Views 10242
Downloads 11045
Data volume 12.7 GB5.4 GB
Unique views 9440
Unique downloads 146

Share

Cite as