Down the memory rabbit hole
summary
Shows that Swift collections use copy-on-write implemented by a private class storage and checked with isUniquelyReferenced to avoid needless copies. Measuring a small Vector copy costs about 500 ns; large structs cost much more, while a class copy (pointer + refcount) is faster. Implements a Storage class plus computed accessors and explains the underscore modify accessor that yields a mutable reference to avoid double-copying computed properties. Warns about complexity, pitfalls with enums and wrappers, and recommends profiling with Xcode Instruments before optimizing.
AI-written summary · about
chapters (7)
- 0:00Start
- 1:34Value Semantics
- 2:03Classes
- 4:21Summary
- 5:02Performances
- 6:41How Long Does It Take To Duplicate a Class
- 21:08Benchmark Your Code








