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

ResourceHelpers.GetBlocks: try to reduce allocations #9

Open
carmineos opened this issue Dec 23, 2020 · 1 comment
Open

ResourceHelpers.GetBlocks: try to reduce allocations #9

carmineos opened this issue Dec 23, 2020 · 1 comment

Comments

@carmineos
Copy link
Owner

Try to reduce allocations when GetReferences and GetParts are invoked.

@carmineos
Copy link
Owner Author

A possible change could be editing both GetParts and GetReferences to take directly an HashSet as parameter

public override void GetParts(HashSet<Tuple<long, IResourceBlock>> blocks)
{
    base.GetParts(blocks);
    // Add parts to the hashset
}

public override void GetReferences(HashSet<IResourceBlock> blocks)
{
    base.GetReferences(blocks);
    // Add references to the hashset
}

which would also require the setter of BlockPosition to create a temporary HashSet

public virtual long BlockPosition
{
    get
    {
        return position;
    }
    set
    {
        position = value;
        var parts = new HashSet<Tuple<long, IResourceBlock>>();
        GetParts(parts);
        foreach (var part in parts)
        {
            part.Item2.BlockPosition = value + part.Item1;
        }
    }
}

@carmineos carmineos pinned this issue Sep 30, 2021
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

1 participant