Optimizing Collections

A new Swift book is out: Optimzing Collections by Károly Lőrentey. I had a small part in this as the bookʼs technical reviewer, and I highly recommend it.

Károly first released the book as a beta version a few months ago and now the final version has been published through objc.io.

Youʼll learn:

  • How to write a custom collection type that conforms to Swiftʼs Collection protocols.
  • How to implement value semantics with copy-on-write behavior in your own types.
  • How to measure the performance of your custom collection and make it a lot faster than the built-in collection types (for certain tasks; different data structures make different tradeoffs).

This isnʼt a book that just scratches the surface. Károly really goes into detail, especially on that last point. I love how practially every chapter ends with a set of charts illustrating the performance characteristics of the code written in that chapter — and those results in turn form the basis for subsequent optimizations in the next chapter.

If you want to get a feel for the book, watch Károlyʼs talk at dotSwift 2017. If you like the talk and would like to learn more, I guarantee youʼll love the book.

Lastly, I think the book is a very nice companion to Advanced Swift. Collections also play a big role in Advanced Swift, but with a different focus: we explore the collection protocols in more detail, but we donʼt discuss the performance aspects at the level of Optimizing Collections.