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

Memory usage optimization with chunks #569

Merged
merged 2 commits into from Oct 5, 2017

Conversation

Projects
None yet
2 participants
@momothereal
Member

momothereal commented Oct 3, 2017

The goal of this PR is to lower the usage of memory by certain objects. Using a profiler, I noticed that over 75% of the memory usage was made of GlowChunk$Key objects, which are used to index chunks by their coordinates in multiple places in the code.

Since objects take more place than primitive types like ints, I tried caching these keys by having a simple permanent hash attributed to them (x * 31 + z) and storing them in a concurrent map. I noticed that not only the amount of GlowChunk$Key objects was reduced considerably (from 5 million to 1600 in a fresh world), but the RAM usage in bytes was lowered because most of these objects were replaced with single integers.

I have also noticed that there are many GlowBlock objects being created and deleted constantly, probably because this type is never cached. I didn't try much in that area yet, but there might be some more stuff to fix as well.

I am no optimization expert, so I am just analyzing graphs over time here. Please feel free to suggest anything or review my attempts if they feel inappropriate.

PS: I didn't really take the time to properly format/beautify my code, sorry in advance :)

@momothereal

This comment has been minimized.

Show comment
Hide comment
@momothereal

momothereal Oct 4, 2017

Member

I just realized I named the branch "chunk-optmimization" by accident. This is why I shouldn't be working on stuff like this at 1 in the morning :)

Member

momothereal commented Oct 4, 2017

I just realized I named the branch "chunk-optmimization" by accident. This is why I shouldn't be working on stuff like this at 1 in the morning :)

@Postremus

Looks mostly good so far.

@Postremus

This comment has been minimized.

Show comment
Hide comment
@Postremus

Postremus Oct 5, 2017

Contributor

thank you.

Contributor

Postremus commented Oct 5, 2017

thank you.

@Postremus Postremus merged commit 12ed57c into master Oct 5, 2017

2 checks passed

ci/circleci Your tests passed on CircleCI!
Details
license/cla Contributor License Agreement is signed.
Details

@momothereal momothereal deleted the chunk-optmimization branch Oct 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment