This PR fixes an issue I actually originally noted & patched in 1.12.2, and then encountered on 1.20.1 when trying out the new ProjectRed beta. The logic to suppress moving blocks runs through quite a bit of logic on every single block in the world, which has a measurable hit to chunk meshing performance (see below profiler screenshot).
To solve this I made a number of optimizations, tailored for the common case of there being no structures in the world:
Added a direct getter for the client level's MovementManager that skips needing to check if the level is client-side, and also skips creating the movement manager if it doesn't exist.
Make the maps from dimension to MovementManager use identity equality & hashing, for slightly better lookup performance.
Bail out early from MovingBlockSuppressorRenderer#canHandleBlock if the movement manager is not tracking any moving structures.
Hoist retrieval of the MovementManager to a local variable in canHandleBlock, so it doesn't need to be re-retrieved for the block position & all adjacent positions.
This code could be optimized further to benefit the case where there are structures as well, but the current optimizations are relatively simple & should not break anything, while fully addressing the original issue (see profiling after these changes below).
Sweet! Will check this out and merge it in the morning. I was aware that canHandleBlock is going to run for every block but didn't get around to actually profiling it.
This PR fixes an issue I actually originally noted & patched in 1.12.2, and then encountered on 1.20.1 when trying out the new ProjectRed beta. The logic to suppress moving blocks runs through quite a bit of logic on every single block in the world, which has a measurable hit to chunk meshing performance (see below profiler screenshot).
To solve this I made a number of optimizations, tailored for the common case of there being no structures in the world:
MovementManager
that skips needing to check if the level is client-side, and also skips creating the movement manager if it doesn't exist.MovementManager
use identity equality & hashing, for slightly better lookup performance.MovingBlockSuppressorRenderer#canHandleBlock
if the movement manager is not tracking any moving structures.MovementManager
to a local variable incanHandleBlock
, so it doesn't need to be re-retrieved for the block position & all adjacent positions.This code could be optimized further to benefit the case where there are structures as well, but the current optimizations are relatively simple & should not break anything, while fully addressing the original issue (see profiling after these changes below).