Skip to content
Success

Changes

Summary

  1. Optimize Chunk Saving Memory Allocation and Compression (details)
  2. Don't sleep between chunk saves (details)
Commit da71ee9abd99ea2fbcb844e2a5b4388b8edfeb63 by md_5
Optimize Chunk Saving Memory Allocation and Compression

Minecraft ineffeciently uses OutputStreams by calling .write(int) on the stream.
For Chunks, this is a DeflaterOutputStream, which allocates a single byte EVERY write.

This is causing the server to allocate tons of new byte[1] objects.
Additionally, this is very ineffecient for the Deflate process.

By Buffering Writes the same way it already is Buffering Reads, we will
write to the stream much more effeciently.

Also a more effecient RegionFile zero'ing for new chunks to speed up
new chunk generation.
The file was modifiedCraftBukkit-Patches/0003-Skeleton-API-Implementations.patch
The file was addedCraftBukkit-Patches/0159-More-effecient-RegionFile-zero-ing.patch
The file was modifiedCraftBukkit-Patches/0121-Cross-World-Entity-Teleportation.patch
The file was modifiedCraftBukkit-Patches/0038-Add-Getter-for-Entity-Invulnerability.patch
The file was addedCraftBukkit-Patches/0158-Optimize-Chunk-Saving-Memory-Allocation-and-Compress.patch
Commit 76236cb74c4a1fe1a3e1b8e49b0540584b13ef08 by md_5
Don't sleep between chunk saves

For some unknown reason, Minecraft is sleeping 10ms between every single chunk being saved to disk.
Under high chunk load/unload activity (lots of movement / teleporting), this causes the chunk unload queue
to build up in size.

This has multiple impacts:
1) Performance of the unload queue itself - The save thread is pretty ineffecient for how it accesses it
   By letting the queue get larger, checking and popping work off the queue can get less performant.
2) Performance of chunk loading - As with #1, chunk loads also have to check this queue when loading
   chunk data so that it doesn't load stale data if new data is pending write to disk.
3) Memory Usage - The entire chunk has been serialized to NBT, and now sits in this queue. This leads to
   elevated memory usage, and then the objects used in the serialization sit around longer than needed,
   resulting in promotion to Old Generation instead of dying young.

If there is work to do, then the thread should be doing its work, and only sleep when it is done.
The file was addedCraftBukkit-Patches/0160-Don-t-sleep-between-chunk-saves.patch
The file was modifiedCraftBukkit-Patches/0002-mc-dev-imports.patch