Hasty Briefsbeta

Bilingual

Every Byte Matters

8 hours ago
  • #hardware awareness
  • #performance
  • #memory optimization
  • Programmers often overlook the impact of field size on performance, focusing instead on algorithmic complexity.
  • Cache line size is 64 bytes; reading a single byte loads the entire line, making spatial locality important.
  • Array of Structs (AoS) can waste cache space, while Struct of Arrays (SoA) packs data more efficiently, yielding up to 30x speed improvements.
  • Sequential access benefits from CPU prefetching, but random access patterns in structures like hash maps rely on the entire working set fitting in cache.
  • Larger struct sizes push data into slower cache levels, significantly increasing latency, especially as the working set grows.