Case classes ate my RAM
summary
Case-class-heavy Scala heaps turn out to store tiny payloads and huge object overhead: a four-char String + long case class lands around ~72 bytes while naïve lists converge to ~96 bytes per element; packing cuts that to ~19–31 bytes per element in benchmarks. The author uses JOL and a Java agent to measure, Shapeless-based derivation to serialize case classes into Array[Byte], and implements scala-packed packed collections (immutable arrays and open-addressing maps). Memory drops by an order of magnitude at the cost of some CPU slowdown; prototype works but remains under further testing before production use.
AI-written summary · about
chapters (21)
- 0:00Introduction
- 1:34Memory challenges with user data
- 2:15Case classes memory costs
- 5:11JOL memory layout analysis
- 7:18Case classes in collections impact
- 8:25JAMM memory usage measurement
- 9:52C++ versus JVM memory
- 11:20Can JVM match C++?
- 12:04Project Valhalla exploration
- 13:53JVM optimization limits
- 14:16Scallop Act introduction
- 15:00Scallop Act code demo
- 18:45Shapeless serialization
- 21:17Custom collections integration
- 27:48Packed collections memory layout
- 30:40Packed maps implementation
- 32:44Packed collections trade-offs
- 35:11Performance benchmarks
- 39:05Production use and plans
- 40:30Resources and tools
- 41:22Q&A








