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="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://datacite.org/schema/kernel-4" xsi:schemaLocation="http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4.1/metadata.xsd">
  <identifier identifierType="DOI">10.5281/zenodo.3370076</identifier>
  <creators>
    <creator>
      <creatorName>Barik, Rajkishore</creatorName>
      <givenName>Rajkishore</givenName>
      <familyName>Barik</familyName>
      <affiliation>Uber Technologies Inc.</affiliation>
    </creator>
    <creator>
      <creatorName>Sridharan, Manu</creatorName>
      <givenName>Manu</givenName>
      <familyName>Sridharan</familyName>
      <affiliation>University of California, Riverside</affiliation>
    </creator>
    <creator>
      <creatorName>Ramanathan, Murali Krishna</creatorName>
      <givenName>Murali Krishna</givenName>
      <familyName>Ramanathan</familyName>
      <affiliation>Uber Technologies Inc.</affiliation>
    </creator>
    <creator>
      <creatorName>Chabbi, Murali</creatorName>
      <givenName>Murali</givenName>
      <familyName>Chabbi</familyName>
      <affiliation>Uber Technologies Inc.</affiliation>
    </creator>
  </creators>
  <titles>
    <title>Optimization of Swift Protocols</title>
  </titles>
  <publisher>Zenodo</publisher>
  <publicationYear>2019</publicationYear>
  <dates>
    <date dateType="Issued">2019-08-12</date>
  </dates>
  <language>en</language>
  <resourceType resourceTypeGeneral="ConferencePaper"/>
  <alternateIdentifiers>
    <alternateIdentifier alternateIdentifierType="url">https://zenodo.org/record/3370076</alternateIdentifier>
  </alternateIdentifiers>
  <relatedIdentifiers>
    <relatedIdentifier relatedIdentifierType="DOI" relationType="IsVersionOf">10.5281/zenodo.3366379</relatedIdentifier>
  </relatedIdentifiers>
  <rightsList>
    <rights rightsURI="https://creativecommons.org/licenses/by/4.0/legalcode">Creative Commons Attribution 4.0 International</rights>
    <rights rightsURI="info:eu-repo/semantics/openAccess">Open Access</rights>
  </rightsList>
  <descriptions>
    <description descriptionType="Abstract">&lt;p&gt;Title:&amp;nbsp;Optimization of Swift Protocols&lt;/p&gt;

&lt;p&gt;Abstract:&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>
  </descriptions>
</resource>
190
130
views
downloads
All versions This version
Views 19057
Downloads 13030
Data volume 15.8 GB3.0 GB
Unique views 17355
Unique downloads 3410

Share

Cite as