Optimization of swift protocols

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 a large industrial app from Uber, they...

Ausführliche Beschreibung

Gespeichert in:
Bibliographische Detailangaben
Veröffentlicht in:Proceedings of ACM on programming languages 2019-10, Vol.3 (OOPSLA), p.1-27
Hauptverfasser: Barik, Rajkishore, Sridharan, Manu, Ramanathan, Murali Krishna, Chabbi, Milind
Format: Artikel
Sprache:eng
Online-Zugang:Volltext
Tags: Tag hinzufügen
Keine Tags, Fügen Sie den ersten Tag hinzu!
container_end_page 27
container_issue OOPSLA
container_start_page 1
container_title Proceedings of ACM on programming languages
container_volume 3
creator Barik, Rajkishore
Sridharan, Manu
Ramanathan, Murali Krishna
Chabbi, Milind
description 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 a large industrial app from Uber, 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 to reduce the overhead of Swift protocols. Within a procedure, we define LocalVar, a dataflow 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 from Uber 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.
doi_str_mv 10.1145/3360590
format Article
fullrecord <record><control><sourceid>crossref</sourceid><recordid>TN_cdi_crossref_primary_10_1145_3360590</recordid><sourceformat>XML</sourceformat><sourcesystem>PC</sourcesystem><sourcerecordid>10_1145_3360590</sourcerecordid><originalsourceid>FETCH-LOGICAL-c220t-47d2205ebdb2c114943526ed05bd464d0cc19cdb5508434cdf88ff6a47c770753</originalsourceid><addsrcrecordid>eNpNj8FKAzEURUNRaKnFT-jsXI2-JO9NJkspaoVCN7oeZl4mEGmbIQmIfr0Vu3B17upyjhC3Eu6lRHrQugGyMBMLhYZqiUpe_dtzscr5AwCk1dhquxDr_VTCMXz3JcRTFX2VP4Mv1ZRiiRwP-UZc-_6Qx9WFS_H-_PS22da7_cvr5nFXs1JQajTuTBoHNyg-m1jUpJrRAQ0OG3TALC27gQha1MjOt633TY-GjQFDeinu_n45xZzT6LsphWOfvjoJ3W9ad0nTPyhFPnY</addsrcrecordid><sourcetype>Aggregation Database</sourcetype><iscdi>true</iscdi><recordtype>article</recordtype></control><display><type>article</type><title>Optimization of swift protocols</title><source>ACM Digital Library Complete</source><source>Elektronische Zeitschriftenbibliothek - Frei zugängliche E-Journals</source><creator>Barik, Rajkishore ; Sridharan, Manu ; Ramanathan, Murali Krishna ; Chabbi, Milind</creator><creatorcontrib>Barik, Rajkishore ; Sridharan, Manu ; Ramanathan, Murali Krishna ; Chabbi, Milind</creatorcontrib><description>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 a large industrial app from Uber, 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 to reduce the overhead of Swift protocols. Within a procedure, we define LocalVar, a dataflow 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 from Uber 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.</description><identifier>ISSN: 2475-1421</identifier><identifier>EISSN: 2475-1421</identifier><identifier>DOI: 10.1145/3360590</identifier><language>eng</language><ispartof>Proceedings of ACM on programming languages, 2019-10, Vol.3 (OOPSLA), p.1-27</ispartof><lds50>peer_reviewed</lds50><oa>free_for_read</oa><woscitedreferencessubscribed>false</woscitedreferencessubscribed><cites>FETCH-LOGICAL-c220t-47d2205ebdb2c114943526ed05bd464d0cc19cdb5508434cdf88ff6a47c770753</cites></display><links><openurl>$$Topenurl_article</openurl><openurlfulltext>$$Topenurlfull_article</openurlfulltext><thumbnail>$$Tsyndetics_thumb_exl</thumbnail><link.rule.ids>314,776,780,27901,27902</link.rule.ids></links><search><creatorcontrib>Barik, Rajkishore</creatorcontrib><creatorcontrib>Sridharan, Manu</creatorcontrib><creatorcontrib>Ramanathan, Murali Krishna</creatorcontrib><creatorcontrib>Chabbi, Milind</creatorcontrib><title>Optimization of swift protocols</title><title>Proceedings of ACM on programming languages</title><description>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 a large industrial app from Uber, 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 to reduce the overhead of Swift protocols. Within a procedure, we define LocalVar, a dataflow 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 from Uber 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.</description><issn>2475-1421</issn><issn>2475-1421</issn><fulltext>true</fulltext><rsrctype>article</rsrctype><creationdate>2019</creationdate><recordtype>article</recordtype><recordid>eNpNj8FKAzEURUNRaKnFT-jsXI2-JO9NJkspaoVCN7oeZl4mEGmbIQmIfr0Vu3B17upyjhC3Eu6lRHrQugGyMBMLhYZqiUpe_dtzscr5AwCk1dhquxDr_VTCMXz3JcRTFX2VP4Mv1ZRiiRwP-UZc-_6Qx9WFS_H-_PS22da7_cvr5nFXs1JQajTuTBoHNyg-m1jUpJrRAQ0OG3TALC27gQha1MjOt633TY-GjQFDeinu_n45xZzT6LsphWOfvjoJ3W9ad0nTPyhFPnY</recordid><startdate>20191001</startdate><enddate>20191001</enddate><creator>Barik, Rajkishore</creator><creator>Sridharan, Manu</creator><creator>Ramanathan, Murali Krishna</creator><creator>Chabbi, Milind</creator><scope>AAYXX</scope><scope>CITATION</scope></search><sort><creationdate>20191001</creationdate><title>Optimization of swift protocols</title><author>Barik, Rajkishore ; Sridharan, Manu ; Ramanathan, Murali Krishna ; Chabbi, Milind</author></sort><facets><frbrtype>5</frbrtype><frbrgroupid>cdi_FETCH-LOGICAL-c220t-47d2205ebdb2c114943526ed05bd464d0cc19cdb5508434cdf88ff6a47c770753</frbrgroupid><rsrctype>articles</rsrctype><prefilter>articles</prefilter><language>eng</language><creationdate>2019</creationdate><toplevel>peer_reviewed</toplevel><toplevel>online_resources</toplevel><creatorcontrib>Barik, Rajkishore</creatorcontrib><creatorcontrib>Sridharan, Manu</creatorcontrib><creatorcontrib>Ramanathan, Murali Krishna</creatorcontrib><creatorcontrib>Chabbi, Milind</creatorcontrib><collection>CrossRef</collection><jtitle>Proceedings of ACM on programming languages</jtitle></facets><delivery><delcategory>Remote Search Resource</delcategory><fulltext>fulltext</fulltext></delivery><addata><au>Barik, Rajkishore</au><au>Sridharan, Manu</au><au>Ramanathan, Murali Krishna</au><au>Chabbi, Milind</au><format>journal</format><genre>article</genre><ristype>JOUR</ristype><atitle>Optimization of swift protocols</atitle><jtitle>Proceedings of ACM on programming languages</jtitle><date>2019-10-01</date><risdate>2019</risdate><volume>3</volume><issue>OOPSLA</issue><spage>1</spage><epage>27</epage><pages>1-27</pages><issn>2475-1421</issn><eissn>2475-1421</eissn><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 a large industrial app from Uber, 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 to reduce the overhead of Swift protocols. Within a procedure, we define LocalVar, a dataflow 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 from Uber 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.</abstract><doi>10.1145/3360590</doi><tpages>27</tpages><oa>free_for_read</oa></addata></record>
fulltext fulltext
identifier ISSN: 2475-1421
ispartof Proceedings of ACM on programming languages, 2019-10, Vol.3 (OOPSLA), p.1-27
issn 2475-1421
2475-1421
language eng
recordid cdi_crossref_primary_10_1145_3360590
source ACM Digital Library Complete; Elektronische Zeitschriftenbibliothek - Frei zugängliche E-Journals
title Optimization of swift protocols
url https://sfx.bib-bvb.de/sfx_tum?ctx_ver=Z39.88-2004&ctx_enc=info:ofi/enc:UTF-8&ctx_tim=2025-02-03T05%3A40%3A44IST&url_ver=Z39.88-2004&url_ctx_fmt=infofi/fmt:kev:mtx:ctx&rfr_id=info:sid/primo.exlibrisgroup.com:primo3-Article-crossref&rft_val_fmt=info:ofi/fmt:kev:mtx:journal&rft.genre=article&rft.atitle=Optimization%20of%20swift%20protocols&rft.jtitle=Proceedings%20of%20ACM%20on%20programming%20languages&rft.au=Barik,%20Rajkishore&rft.date=2019-10-01&rft.volume=3&rft.issue=OOPSLA&rft.spage=1&rft.epage=27&rft.pages=1-27&rft.issn=2475-1421&rft.eissn=2475-1421&rft_id=info:doi/10.1145/3360590&rft_dat=%3Ccrossref%3E10_1145_3360590%3C/crossref%3E%3Curl%3E%3C/url%3E&disable_directlink=true&sfx.directlink=off&sfx.report_link=0&rft_id=info:oai/&rft_id=info:pmid/&rfr_iscdi=true