skip to main content
10.1145/3133841.3133843acmconferencesArticle/Chapter ViewAbstractPublication PagessplashConference Proceedingsconference-collections
research-article

Dynamic atomicity: optimizing swift memory management

Published:24 October 2017Publication History

ABSTRACT

Swift is a modern multi-paradigm programming language with an extensive developer community and open source ecosystem. Swift 3's memory management strategy is based on Automatic Reference Counting (ARC) augmented with unsafe APIs for manually-managed memory. We have seen ARC consume as much as 80% of program execution time. A significant portion of ARC's direct performance cost can be attributed to its use of atomic machine instructions to protect reference count updates from data races. Consequently, we have designed and implemented dynamic atomicity, an optimization which safely replaces atomic reference-counting operations with nonatomic ones where feasible. The optimization introduces a store barrier to detect possibly intra-thread references, compiler-generated recursive reference-tracers to find all affected objects, and a bit of state in each reference count to encode its atomicity requirements.

Using a suite of 171 microbenchmarks, 9 programs from the Computer Language Benchmarks Game, and the Richards benchmark, we performed a limit study by unsafely making all reference counting operations nonatomic. We measured potential speedups of up to 220% on the microbenchmarks, 120% on the Benchmarks Game and 70% on Richards.

By automatically reducing ARC overhead, our optimization both improves Swift 3's performance and reduces the temptation for performance-oriented programmers to resort to unsafe manual memory management. Furthermore, the machinery implemented for dynamic atomicity could also be employed to obtain cheaper thread-safe Swift data structures, or to augment ARC with optional cycle detection or a backup tracing garbage collector.

References

  1. Apple. 2016. The Swift Programming Language (Swift 3.1 ed.). Apple Inc.Google ScholarGoogle Scholar
  2. ARC 2012. Objective-C Automatic Reference Counting (ARC). http://clang.llvm.org/docs/AutomaticReferenceCounting.html. (2012).Google ScholarGoogle Scholar
  3. Stephen M. Blackburn and Kathryn S. McKinley. 2003. Ulterior Reference Counting: Fast Garbage Collection Without a Long Wait. In Proceedings of the Conference on Object-oriented Programing, Systems, Languages, and Applications. Anaheim, California, 344-358. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. D. C. Cann and Rod R. Oldehoeft. 1988. Reference Count and Copy Elimination for Parallel Applicative Computing. Technical Report CS-88-129. Department of Computer Science, Colorado State University, Fort Collins, CO.Google ScholarGoogle Scholar
  5. CLBG 2008. Computer Language Benchmarks Game. http://benchmarksgame.alioth.debian.org/. (2008).Google ScholarGoogle Scholar
  6. Benoit Daloze, Stefan Marr, Daniele Bonetta, and Hanspeter Mössenböck. 2016. Efficient and Thread-safe Objects for Dynamically-typed Languages. In Proceedings of the 2016 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA 2016). ACM, New York, NY, USA, 642-659. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. John DeTreville. 1990. Experience with concurrent garbage collectors for Modula-2+. Technical Report 64. DEC Systems Research Center.Google ScholarGoogle Scholar
  8. L. Peter Deutsch and Daniel G. Bobrow. 1976. An Efficient, Incremental, Automatic Garbage Collector. Commun. ACM 19, 9 (Sept. 1976), 522-526. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Tamar Domani, Gal Goldshtein, Elliot K. Kolodner, Ethan Lewis, Erez Petrank, and Dafna Sheinwald. 2002. Thread-local Heaps for Java. In Proceedings of the 3rd International Symposium on Memory Management (ISMM '02). ACM, New York, NY, USA, 76-87. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. GCD 2017. Dispatch. https://developer.apple.com/reference/dispatch. (2017).Google ScholarGoogle Scholar
  11. Pramod G. Joisha. 2006. Compiler Optimizations for Nondeferred Reference: Counting Garbage Collection. In Proceedings of the 5th International Symposium on Memory Management (ISMM '06). ACM, New York, NY, USA, 150-161. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Richard Jones, Antony Hosking, and Eliot Moss. 2011. The Garbage Collection Handbook: The Art of Automatic Memory Management (1st ed.). Chapman & Hall/CRC. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Joseph Levanoni and Erez Petrank. 1999. A Scalable Reference Counting Garbage Collector. Technical Report.Google ScholarGoogle Scholar
  14. Richards 1999. Richards Benchmark. http://www.cl.cam.ac.uk/mr10/Bench.html. (1999).Google ScholarGoogle Scholar
  15. Swift 2017. Swift Ownership Manifesto. https://github.com/apple/swift/blob/master/docs/OwnershipManifesto.md. (2017).Google ScholarGoogle Scholar
  16. David Ungar. 1984. Generation Scavenging: A Non-disruptive High Performance Storage Reclamation Algorithm. In Proceedings of the First ACM SIGSOFT/SIGPLAN Software Engineering Symposium on Practical Software Development Environments (SDE 1). ACM, New York, NY, USA, 157-167. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. David Ungar and David Grove. 2017a. Swift Computer Language Benchmarks Game variants. https://github.com/davidungar/benchmarkingswift/tree/Swift_3.2/ComputerLanguageBenchmarkGame. (2017).Google ScholarGoogle Scholar
  18. David Ungar and David Grove. 2017b. Swift Dynamic Atomicity Implementation. https://github.com/davidungar/Swift-dynamic-atomicity. (2017).Google ScholarGoogle Scholar
  19. David Ungar and David Grove. 2017c. Swift Richards Benchmark. https://github.com/davidungar/benchmarkingswift/tree/Swift_3.2/Richards. (2017).Google ScholarGoogle Scholar

Index Terms

  1. Dynamic atomicity: optimizing swift memory management

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in
        • Published in

          cover image ACM Conferences
          DLS 2017: Proceedings of the 13th ACM SIGPLAN International Symposium on on Dynamic Languages
          October 2017
          86 pages
          ISBN:9781450355261
          DOI:10.1145/3133841

          Copyright © 2017 ACM

          Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 24 October 2017

          Permissions

          Request permissions about this article.

          Request Permissions

          Check for updates

          Qualifiers

          • research-article

          Acceptance Rates

          Overall Acceptance Rate32of77submissions,42%

          Upcoming Conference

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader