Abstract list that doesn't get reconstructed every time it's accessed?

Keywords: c#


I'm making a game with collision detection. This collision detection runs 250 times per second (with some optimalizations, but that's irrelevant).

There are ships, and each ship has a precisely defined complex collision body to make sure collisions are nearly 1:1 with the visual model.

Because every ship should provide its own set of collision points, I made an abstract property, which looks like this overriden:

public override List<CollisionShape> CollisionBody => new List<CollisionShape>
    // top sharp edges
    new CollisionShape(new Vector2(0.3f, 0.035f), 0.8f),
    new CollisionShape(new Vector2(0.7f, 0.035f), 0.8f),
    // wings top-down
    new CollisionShape(new Vector2(0.24f, 0.15f), 3),
    new CollisionShape(new Vector2(0.76f, 0.15f), 3),
    new CollisionShape(new Vector2(0.18f, 0.3f), 5),
    new CollisionShape(new Vector2(0.82f, 0.3f), 5),
    new CollisionShape(new Vector2(0.105f, 0.4f), 4),
    new CollisionShape(new Vector2(0.895f, 0.4f), 4),
    new CollisionShape(new Vector2(0.17f, 0.6f), 9),
    new CollisionShape(new Vector2(0.83f, 0.6f), 9),
    new CollisionShape(new Vector2(0.21f, 0.81f), 6),
    new CollisionShape(new Vector2(0.79f, 0.81f), 6),
    // bottom sharp edges
    new CollisionShape(new Vector2(0.21f, 0.97f), 0.5f),
    new CollisionShape(new Vector2(0.79f, 0.97f), 0.5f),
    // main body
    new CollisionShape(new Vector2(0.5f, 0.4f), 8),
    new CollisionShape(new Vector2(0.5f, 0.67f), 9),
    new CollisionShape(new Vector2(0.35f, 0.425f), 4),
    new CollisionShape(new Vector2(0.65f, 0.425f), 4),
    new CollisionShape(new Vector2(0.38f, 0.77f), 3),
    new CollisionShape(new Vector2(0.62f, 0.77f), 3)

This is one of the simpler ones.

What I noticed while debugging, is that this List gets reconstructed 250 times per second per bullet. When there's a few bullets close-up, it could mean over a thousand times per second that this list is reconstructed. Surprisingly performance doesn't get hit by this in a noticable way? Maybe it detects it doesn't need to reconstruct and optimizes itself? I kind

I thought about requiring the collision body in the constructor, but because I'm using some reflection-activation for listing all the ships, it just wont work. I also want to make sure it's required to provide the collision body set, and the only way to do that is through abstract properties. I feel like I'm either missing an obvious solution or thinking the wrong way around. I feel like there has to be a way to define a property in a way as to not reconstruct it every time, because otherwise someone somewhere on the Internet would've already asked this question, and I didn't find anything.. I just feel like I'm doing something so plain stupid wrong.

So, is there a way to keep this abstract property while not reconstructing the List every time it's accessed?