❔ Excessive runtime allocation using Dictionary with struct key TryGetValue

Doing some optimization testing using spatial partitioning of 2D scenes and have hit a weird runtime allocation problem that I've tracked down to Dictionary.TryGetValue.
I am storing Chunk instances in a Dictionary with a custom int2 struct type that implements IEquatable.

Here's my index type:
public struct ChunkCoord : IEquatable<ChunkCoord>
        {
            public int X { get; set; }
            public int Y { get; set; }

            public ChunkCoord(int x, int y)
            {
                X = x;
                Y = y;
            }

            public bool Equals(ChunkCoord coord)
            {
                return X == coord.X && Y == coord.Y;
            }
        }


Any tips to fix or avoid this?
devenv_m8oSert9Tj.png
Was this page helpful?