Hacker News new | ask | show | jobs
by UK-AL 5121 days ago
I don't get it, what's oo got to do with storing entities in column major storage. Store the objects in a 2d array.

Normally you don't even store entities like that, I've seen all sorts of crazy data structures, such as storing them spatially, so you can ignore visual updates.

Or am I completely not getting what your saying here...

1 comments

Polymorphism with objects implies an indirection to data with variable size, and also usually an object graph involving pointer chasing; lots of indirection is bad for performance. Also, cache-efficient manipulation favours non-indirected, tightly-packed data.

So instead of:

  class Entity { Vector location; Foo foo; Vector velocity; }; // etc.
  Entities[] entities;
One prefers:

  Vector[] locations;
  Vector[] velocities;
  Foo[] foos;
A physics engine updating locations and velocities won't waste cache on redundant information (like foo) in this case.

There was an excellent presentation (from some games conference) on this topic posted here on HN a few years ago, but I can't find it easily.

Informative reply.