Cinderscapes
Cinderscapes copied to clipboard
Optimize tickAsh method in MixinServerWorld
Fixes:
In server environments, cinderscapes can eat 2-5+ percent of server thread time running it's tickAsh
method. This PR optimizes that method heavily. Below screenshot is from a 1.20.1 server, but the same method is utilized in 1.20.5, and the same problems are present.
Causes:
- The previous implementation of
tickAsh
runsgetBiome(pos)
potentially dozens of times per randomTick, which is a very expensive operation in high quantities. - The mixin does not short-circuit if the ServerWorld dimension isn't the Nether, causing (failed)
getBiome
checks in every dimension regardless if the biome exists there at all. Ashy Shoals is only added to the Nether, it should only run in the Nether. - BlockPos operations don't make use of the faster operations of
BlockPos.Mutable
, instead using.up()
extensively, which is a method from the ImmutableBlockPos
- Redundant calls to
pos.up
andisSideSolidFullSquare
Implementation
- Short circuit if the dim isn't the Nether
- Redesigned the check into a for loop. Loop design dispenses with the need for any allocation of
state
orbiome
. - Removes redundant check to
isSideSolidFullSquare
, as thecanPlaceAt
check does this already. - simplified if statement into it's own method.
- Optimized
blockAbove
by using theMutable.setY
method to avoid repeated allocation of new BlockPos - Only check for biomes if every other condition is met.
Opportunities
-
blockAbove
is a pretty expensive method, as it's iterating to (typically) the same block over and over again while checking every blockstate on the way. Some method to cache the "block above" would be beneficial, only re-utilizingblockAbove
when the iterator is above the previously cached blockstate - Since I've already demonstrated decent performance improvements in profiling on my Singleplayer test, this doesn't seem critical
Singleplayer before (1.20.1 build)
Singleplayer after (1.20.1 build)