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

Passed down tile for carve to avoid lock hits when grabbing the tile … #414

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

qf200011
Copy link

@qf200011 qf200011 commented Jul 7, 2024

When doing the carve step of the cave layer, the tile used to be grabbed from the dimension

final int terrainHeight = dimension.getIntHeightAt(x, y);

This is problematic because within getIntHeightAt, we would get the tile by calling getTile

public int getIntHeightAt(int x, int y, int defaultHeight) { Tile tile = getTile(x >> TILE_SIZE_BITS, y >> TILE_SIZE_BITS); if (tile != null) { return tile.getIntHeight(x & TILE_SIZE_MASK, y & TILE_SIZE_MASK); } else { return defaultHeight; } }

getTile will return the tile properly but it first has to get a lock before doing so.

public Tile getTile(final int x, final int y) { readLock.lock(); try { return tiles.get(new Point(x, y)); } finally { readLock.unlock(); } }

Because getting a lock and releasing it is relativly intensive when being done frequently, a large amount CPU time was spent just getting and releasing the lock.

After the changes which passes the tile down a few steps, the carve step of cave was reduced in cpu time by 57%.

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

Successfully merging this pull request may close these issues.

1 participant