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

Removed broken chunk key optimization, use longs instead #586

Merged
merged 4 commits into from
Nov 22, 2017

Conversation

smartboyathome
Copy link
Contributor

As discussed in discord, the chunk key class implemented its caching mechanism wrong. By doing (x * 31 + z), it was confusing the chunks at (1, 0) and (0, 31) for each other. This, I observed, lead to corruption in the saved chunks. I ported over Momo's use of longs for chunk keys, which in my testing is not observedly slower than the existing code.

@@ -251,14 +250,14 @@ public LightningStrike strikeLightningEffect(Location loc, boolean isSilent) {
* Per-chunk spawn limits on various types of entities.
*/
private int monsterLimit, animalLimit, waterAnimalLimit, ambientLimit;
private Map<Integer, GlowStructure> structures;
private Map<Long, GlowStructure> structures;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps TLongObjectMap could be better here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're talking about the trove stuff, correct? I hadn't seen it used anywhere else in the code base, and this is already pretty lean as it is. I try not to do too much premature optimization, and in this case I don't think we'll be storing millions of items in the map. In addition, while Trove is stable, it seems within the last couple years other libraries outperform it.


/**
* The maximum height at which players may place blocks.
*/
private int maxBuildHeight;

private Set<Key> activeChunksSet = new HashSet<>();
private Set<Long> activeChunksSet = new HashSet<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or TLongSet here?

@smartboyathome
Copy link
Contributor Author

After much discussion, I scaled back the change so it only affected GlowChunk.ChunkKeyStore and GlowChunk.Key, preserving them rather than replacing them. We can observe how this affects memory/performance, and go from there.

In addition, I had to make a tweak to GlowPlayer due to some changes introduced in Glowkit that prevented Glowstone from compiling.

@mastercoms mastercoms merged commit eaf1dfb into GlowstoneMC:master Nov 22, 2017
@smartboyathome smartboyathome deleted the chunk_fixing branch December 7, 2017 16:46
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.

None yet

3 participants