Skip to content

Instantly share code, notes, and snippets.

@ammaraskar
Created March 17, 2018 17:50
Show Gist options
  • Save ammaraskar/e197bc6c6f24e4acbb15c222884c7c70 to your computer and use it in GitHub Desktop.
Save ammaraskar/e197bc6c6f24e4acbb15c222884c7c70 to your computer and use it in GitHub Desktop.
Branch: https://github.com/EcoCityCraft/Spigot/tree/mikeprimm/lighterNibbleArrays
This is an experimental change I've made to try to reduce basic memory use due to chunks. Specifically,
it exploits several facts that I've confirmed (via instrumentation) to be true:
1) The NibbleArrays used for block data are all zero, on a section by section basis, 60+% of the time.
This is largely due to world generated blocks being almost exclusively block data free (stone, dirt, etc).
2) The NibbleArrays used for Emitted lighting data are 90%+ all zeros, due to the fact that most chunk sections don't
contain emitting sources (e.g. lava, torches)
3) The NibbleArrays used for Sky lighting data are 80%+ all zeros OR all 15s, due to the chunk section being below
ground level, or completely above it.
The net result, here, is that a large fraction (70-75%) of the NibbleArrays used for chunk sections are capable of being
represented without actually allocating an array. As these 3 NibbleArrays represent 60% of the allocation of data for blocks
in a chunk section (3 x 4 bits for them, plus 8 bits for the block ID), this translates to a (measured) reduction in memory
use for chunk block data of 40-45%. For one player, this is around 32MB less memory use out of about 77MB on a typical world.
For 10,000 loaded chunks, this will translate to approximately 700MB improvement in true memory use.
There is still some room for improvement here - I want to rework the ChunkSnapshot code to take advantage of the change,
which will help Dynmap and the like - but I think it may be ready for testing by the 'brave souls' out there :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment