alt.hn

6/1/2026 at 10:07:16 PM

Every Byte Matters

https://fzakaria.com/2026/06/01/every-byte-matters

by setheron

6/2/2026 at 6:21:21 AM

This can be optimized further even without struct of arrays:

  struct Monster {
      uint32_t id;          // 4 bytes
      float    x, y, z;     // 12 bytes
      float    vx, vy, vz;  // 12 bytes
      int32_t  hp;          // 4 bytes
      int32_t  attack;      // 4 bytes
      int32_t  defense;     // 4 bytes
      uint8_t  is_alive;    // 1 byte
      uint8_t  team;        // 1 byte
      char     name[22];    // 22 bytes
  };
In many cases 16-bit integers are enough for storing positions and velocities (with carefully tuned range). Other stats can use 16-bit or even 8-bit integers, bit-fields can be used for boolean flags and other small integer values (like team). Storing per-moster name may be not necessary unless they are not monsters but unique NPCs.

The same optimization may also reduce network bandwidth for multiplayer games and save sizes for singleplayer games.

by Panzerschrek

6/2/2026 at 12:03:11 PM

The struct can be optimized but if we keep growing it with our features we hit the same problem for the cache line sequential access.

Smaller structs help with keeping working set down though.

by setheron