Cinderscapes icon indicating copy to clipboard operation
Cinderscapes copied to clipboard

Optimize tickAsh method in MixinServerWorld

Open fzzyhmstrs opened this issue 9 months ago • 0 comments

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. image

Causes:

  • The previous implementation of tickAsh runs getBiome(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 Immutable BlockPos
  • Redundant calls to pos.up and isSideSolidFullSquare

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 or biome.
  • Removes redundant check to isSideSolidFullSquare, as the canPlaceAt check does this already.
  • simplified if statement into it's own method.
  • Optimized blockAbove by using the Mutable.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-utilizing blockAbove 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) image

Singleplayer after (1.20.1 build) image

fzzyhmstrs avatar May 04 '24 03:05 fzzyhmstrs