A Practical Guide to Applying Data-Oriented Design

Andrew Kelley, the author of Zig, presents some ideas on how to make your program faster by reducing the amount of memory used through smart data structure design. This is somewhat of a revelation to me as I tend to sloppily use float64/int everywhere instead of using float32/int32 where I can.


  • Each level of memory is an order of magnitude slower
  • CPUs are fast, but memory is slow
    • Calculate instead of store.
  • Strategy: Identify where you have many objects in memory, and make the size of each object smaller.
  • Use Indexes instead of pointers
  • Store booleans out-of-band
  • MultiArrayList (Struct of Arrays)
  • Eliminate padding with struct-of-arrays
  • Store sparse data in hash maps
  • Use “encodings” instead of OOP/polymorphism
  • program got much faster from simplifying data structures
  • From Q&A
    • 32-bit operations are fast on 64-bit CPUs as they have instructions for 32-bit ops