Paladin's Furniture

Paladin's Furniture

7M Downloads

Huge chunk update stutter when using lots of furniture, MC 1.18.2-latest or more affected, cause and fix included.

Corosauce opened this issue ยท 1 comments

commented

Bug Description

isOptifineLoaded() lacks important class lookup caching, resulting in huge cpu cost when lots of furniture blocks are used:

https://github.com/UnlikePaladin/paladins-furniture/blob/architectury-1.21.4/common/src/main/java/com/unlikepaladin/pfm/PaladinFurnitureMod.java#L101-L108

goes back as far as at least 1.18.2

issue demo 1 100 chairs:

http://share.coros.us/files/pfm_1.mp4

issue demo 2, 300 chairs:

http://share.coros.us/files/pfm_2.mp4

relevant spark profile: https://spark.lucko.me/RyswOA1kw8

piece of interest in the spark profile showing the cpu cost, almost an entire second spent in isOptifineLoaded() during a 18 second profile:

Image

The issue becomes way more obvious when you combine things like Deceased Craft modpack, the biolab uses a lot of this mods furniture, and if you are doing things like holding an offhand torch, its updating a light source near you twice a second, resulting in huge stutters, or anything that does lots of chunk updates.

FIX:

Super easy, just cache the result of Class.forName("net.optifine.shaders.Shaders"), for example you could, in a static block, look up the class and save it in a field, then from there if the field is null, its not installed

eg:

cached lookup: https://github.com/Corosauce/WATUT/blob/1.21.0/src/main/java/com/corosus/watut/client/screen/RenderHelper.java#L54

using the cached lookup: https://github.com/Corosauce/WATUT/blob/1.21.0/src/main/java/com/corosus/watut/client/screen/RenderHelper.java#L117-L120

Reproduction Steps

  • Align yourself at the start of a chunk border, eg 0 0
  • run: /fill ~ ~ ~ ~16 ~0 ~16 pfm:acacia_chair
  • place blocks in that chunk
  • witness frame stutters
  • place more to see worse and worse frame stutters

Log File

No relevant log file

commented

will fix, thanks for bringing this to my attention