Lag caused by flan checking getClaimAt() in ClaimStorage
Wesley1808 opened this issue ยท 1 comments
Issue (The better the description the better i can solve the issue):
Large lagspikes caused by slow getClaimAt() checks in ClaimStorage.
This is very noticeable when firing a lot of pistons or having flowing water, like flush style mobfarms.
Steps to reproduce:
Have large contraptions with lots of pistons fire at the same time. TPS will drop a lot.
Using Spark I have checked this out a bit and it seems the main problem is that for all checks that require to get the claim location ClaimStorage.getClaimAt()
it uses Long2ObjectArrayMap
, which seems unnecessary as Flan doesn't store any arrays in it. I have tested it using another implementation that is much faster, for example Long2ObjectOpenHashMap
, which still seems to work just fine. Is there any reason for Flan to use Long2ObjectArrayMap
that I haven't noticed?
Source: https://github.com/austinv11/Long-Map-Benchmarks
The other thing you can easily optimize is by removing this.claims.containsKey()
and replacing it with a null check after using this.claims.get()
.
get() and containsKey() essentially do the exact same thing, except one returns a boolean if it exists, and the other returns the value.
Affected Versions (Latest is NOT a version):
- Minecraft: 1.17.1
- Fabric(API): 0.37.1
- Flan: 1.5.3 - 1.17 (But in the newest commits this code is no different).