Down the memory rabbit hole to understand the need for a modify keyword 🕵🏿‍♂️

By Denis Poifol

Elevator Pitch

How does swift handle the memory of value types ? whats is copy on writte? why do we need it? and how can a new keyword save us from bad performance? Are all the questions adressed in this talk.

Description

The difference between value type and reference type is key to know when you should create a class or a struct.

But what does it mean for the memory management?

Indeed passing values around instead of pointers, is great for immutability and limiting side effects, but it comes at a cost : calling a function with a value type parameter is going to need from us to pass a copy of the argument, which might take some time. Also there is something really weird when you think about it : Array are value types in swift, but how does swift manage a struct that has a potential infinite number of elements. That is where copy on write comes along. (COW 🐮)

COW is a great but it comes with some performance issues, that need to be fixed with a new modify keyword.

The idea here is to go through the whole though process in order to make it accessible to anyone even people that are new in swift. - Starting with explaining what are the differences between reference and value type, which means talking briefly about Automatic Reference Counting. - Then trying to understand how the memory is managed for value types and the performance cost of it. - Which is going to lead us to wonder how we can make the best of both world using COW. - And finally getting to the current limitations of it and investigate how the new modify keyword in swift is going to save the day.

I do believe this is a really interesting topic and that it is important to cover it because the pitfall of COW is not going to magically fix itself with the appearance of a new keyword, developers will need to know what is under the hood and when they should or should not worry about this performance issues.

This talk is technical and is rich in content so it should last at least 40 minutes.