GridInformationKey should implemented IEquatable<GridInformationKey> and override GetHashCode() to avoid GC alloc
tanghuipang opened this issue · 1 comments
tanghuipang commented
as GridInformationKey used as a Dictionary key, current version will alloc 292B GC when call dict.TryGetValue(). For better performance it should be like below:
internal struct GridInformationKey : IEquatable<GridInformationKey>
{
public Vector3Int position;
public String name;
public bool Equals(GridInformationKey key)
{
return position == key.position && name == key.name;
}
public override int GetHashCode()
{
return position.GetHashCode() + name.GetHashCode();
}
}
ChuanXin-Unity commented
Thanks! We will check out this issue!