MrTJP / ProjectRed

Redstone Engineering
MIT License
474 stars 185 forks source link

Optimize MovingBlockSuppressorRenderer for common case of no structures #1885

Closed embeddedt closed 3 months ago

embeddedt commented 3 months ago

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

2024-07-30_22-15

To solve this I made a number of optimizations, tailored for the common case of there being no structures in the world:

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

2024-07-30_22-21

MrTJP commented 3 months ago

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.

Thanks!