Swift Secrets: Unlocking the Power of 'Any' and 'Some'
summary
Explains that Swift’s any creates an existential container = 40 bytes (64-bit) which stores small structs inline and moves large values to the heap, causing hidden allocations; method calls through existentials use dynamic dispatch via witness table, while some (opaque) avoids the container and keeps static dispatch. Uses the Swift compiler and SIL to show the optimizer can specialize any/some into static calls for monomorphic call sites, but specialization often fails across modules unless symbols are opened or inlinable.
AI-written summary · about
chapters (13)
- 0:00Intro & Agenda
- 1:36“any” and “some” revolution
- 3:05Existential Type’s
- 6:41How Generics working?
- 7:55Protocol abstraction
- 11:45“any” Mechanism with Existential Container
- 13:50Object in Existential Container (struct)
- 16:35Method Dispatch of Existential Container
- 19:01Metadata
- 20:05How Existential Containers actually works?
- 26:00Specialisation of function argument with Generics
- 27:27Limitation of argument Specialization
- 29:15Summary: Optimization








