Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GridInformationKey should implemented IEquatable<GridInformationKey> and override GetHashCode() to avoid GC alloc #344

Open
tanghuipang opened this issue Sep 2, 2022 · 1 comment

Comments

@tanghuipang
Copy link

tanghuipang commented Sep 2, 2022

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
Copy link
Collaborator

Thanks! We will check out this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants