Conference paper Open Access

Optimization of Swift Protocols

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

DataCite XML Export

<?xml version='1.0' encoding='utf-8'?>
<resource xmlns:xsi="" xmlns="" xsi:schemaLocation="">
  <identifier identifierType="DOI">10.5281/zenodo.3370076</identifier>
      <creatorName>Barik, Rajkishore</creatorName>
      <affiliation>Uber Technologies Inc.</affiliation>
      <creatorName>Sridharan, Manu</creatorName>
      <affiliation>University of California, Riverside</affiliation>
      <creatorName>Ramanathan, Murali Krishna</creatorName>
      <givenName>Murali Krishna</givenName>
      <affiliation>Uber Technologies Inc.</affiliation>
      <creatorName>Chabbi, Murali</creatorName>
      <affiliation>Uber Technologies Inc.</affiliation>
    <title>Optimization of Swift Protocols</title>
    <date dateType="Issued">2019-08-12</date>
  <resourceType resourceTypeGeneral="ConferencePaper"/>
    <alternateIdentifier alternateIdentifierType="url"></alternateIdentifier>
    <relatedIdentifier relatedIdentifierType="DOI" relationType="IsVersionOf">10.5281/zenodo.3366379</relatedIdentifier>
    <rights rightsURI="">Creative Commons Attribution 4.0 International</rights>
    <rights rightsURI="info:eu-repo/semantics/openAccess">Open Access</rights>
    <description descriptionType="Abstract">&lt;p&gt;Title:&amp;nbsp;Optimization of Swift Protocols&lt;/p&gt;


&lt;p&gt;Swift, an increasingly-popular programming language, advocates the use of protocols, which define a set of required methods and properties for conforming types. &amp;nbsp;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. &amp;nbsp;Unfortunately, heavy use of protocols can result in significant performance overhead. &amp;nbsp;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.&lt;/p&gt;

&lt;p&gt;In this paper, we describe three new optimizations and transformations we have developed to reduce the overhead of Swift protocols. &amp;nbsp;Within a procedure, we define LocalVar, a data-flow analysis and transformation to remove both dynamic dispatch and boxing overheads. &amp;nbsp;We also describe Param, which optimizes the case of protocol-typed method parameters using specialization. &amp;nbsp;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. &amp;nbsp;We also describe how these optimizations work fruitfully together and with existing Swift optimizations to deliver further speedups.&lt;/p&gt;

&lt;p&gt;We perform elaborate experimentation and demonstrate that our&amp;nbsp;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.&lt;/p&gt;</description>
All versions This version
Views 19057
Downloads 13030
Data volume 15.8 GB3.0 GB
Unique views 17355
Unique downloads 3410


Cite as