How to fit a million stars into an iPhone
summary
Shows how a 208‑byte star record becomes 56 bytes and a 560MB catalog falls to ~130MB by: replacing optionals with sentinel values and getters, switching to smaller integer types, moving small fields first to eliminate alignment gaps, and deduplicating strings into a dictionary with 16‑bit indices. Uses MemoryLayout.size/stride and profiling to guide changes, keeps unit tests to catch regressions, and ships the result as a SceneKit/ARKit viewer plus a server API that runs within a 500MB free tier. packed struct ordering string dictionary with 16‑bit indices MemoryLayout.stride checks
AI-written summary · about
chapters (20)
- 0:00Introduction and motivation
- 1:27Why optimize code
- 3:55Cache misses and performance
- 7:29Memory optimization basics
- 13:58The optimization loop
- 16:29Demo of star database app
- 17:55Problem with large star database
- 19:22Measuring struct memory size
- 21:10Analyzing star struct layout
- 23:38Replacing optionals with raw values
- 27:55Memory alignment and padding
- 30:42Reordering struct fields for efficiency
- 32:27Domain knowledge and string optimization
- 35:42Balancing memory and CPU usage
- 37:13Final optimization results
- 37:57When to apply these optimizations
- 39:22Optimizing Xcode compile times
- 42:18Server-side Swift benefits
- 43:00Key takeaways and conclusion
- 46:14Q&A
related talks
25mThe Life of an Image on iOS
45mReducing App Size: Moving Images and Localization Strings to the Server
48mARK on iOS: Leveraging UE4 for 98% Content Reduction
14mMemory Optimization through Structure Packaging
14mReducing Image Memory Consumption in 10 Minutes
38mShaving off bytes at any scale: Space savings in various subsystems of PostgreSQL
33mOptimization - Making your app faster
33mPruning Your App- Good Practices for Reducing App Size
