Cache Performance Issues
GiantLuigi4 opened this issue · 4 comments
So I was trying to optimize my mod, and while profiling what I assumed was my selection logic being slow, I noticed this instead

I, actually tried using a map based voxel shape cache for my mod before and it ended up hurting performance more than it helped
So seeing this, I'm wondering why C&B is using a map based cache?
From my looking around through the C&B codebase, it looks like the shape should be able to be attached to the IAreaShapeIdentifier to get rid of the VoxelShapeManager entirely
I also noticed that ChiselBlockEntity$Identifier#equals() is invoking toArray, which seems pretty unnecessary?

But ultimately I'd recommend just getting rid of the manager entirely, since even with the equals check order swapped around the impact is noticeable with not all that many chiseled blocks

Could also potentially use the map based cache to de-duplicate data and attach the shape to the IAreaShapeIdentifier to remove the repeated lookups?
The big thing is that this ends up slowing down chunk meshing pretty noticeably, since that does rely on information about the voxel shapes, and is having to do that entire equality check I believe multiple times per chiseled block
Game version: 1.20.1
C&B version: latest for 1.20.1
Based off the github, this exists in the 1.20.4 version and "latest" branch too
Additional note, I would try some of this out on my own but I couldn’t even get the C&B gradle to import
I believe this is fixed by the changes in 6248d7b (specifically around adding a faster cache to the block entity itself); I had previously profiled and mentioned this issue in another discussion.
That commit does look like it’ll help; unsure to what extent
I had previously profiled and mentioned this issue in another discussion.
I’m curious where said discussion is to look through it myself, and I’m gonna guess this is probably also able to considered a duplicate of it to be honest
That commit does look like it’ll help; unsure to what extent
I had previously profiled and mentioned this issue in another discussion.
I’m curious where said discussion is to look through it myself, and I’m gonna guess this is probably also able to considered a duplicate of it to be honest
It is a discussion in a discord you are sadly not part of.
I need a cache because the structure of a C&B block can be massively complicated. An computing simplified VoxelShapes (which mojang needs to do anything performance wise with them), is extremely expensive, to the point where it can hand an entire server if it needs to compute several of them. So the cache basically ensures that if you are standing in an area that has a lot of similarly shaped C&B blocks (which happens quite a lot, with fancy stairs, slab like structures etc) it has to do the compute generally only once.