using jurassic-reborn 1.20.1, forge version 47.4.16, java 17.0.8
there is a serious performance issue in net.vit.jurassicreborn.common.util.EntityColorTint.
the method isEntityInList(Entity) is called during entity rendering and performs a linear scan over a class list using Class.isAssignableFrom every call, with no caching.
this runs per-entity, per-frame, on the render thread.
symptoms:
- spawning as few as 10 vanilla sheep drops fps from ~60 to ~30 when looking at them
- spark profiler shows EntityColorTint.isEntityInList taking ~50–60% of total render time (https://spark.lucko.me/XrbBdL3Mxn)
- issue reproduces even with only vanilla entities (no dinosaurs required, tested on sheep, chicken and cows)
problematic code:
public static boolean isEntityInList(Entity test){
for(Class<? extends Entity> entity : entityClasses){
if(entity.isAssignableFrom(test.getClass())){
return true;
}
}
return false;
}
why this is bad:
proposed fix (tested):
cache results per entity class and invalidate cache when the list changes
private static final Map<Class<? extends Entity>, Boolean> CLASS_CACHE = new HashMap<>();
...
public static boolean isEntityInList(Entity test) {
Class<? extends Entity> clazz = test.getClass();
Boolean cached = CLASS_CACHE.get(clazz);
if (cached != null) return cached;
boolean result = false;
for (Class<? extends Entity> entity : entityClasses) {
if (entity.isAssignableFrom(clazz)) {
result = true;
break;
}
}
CLASS_CACHE.put(clazz, result);
return result;
}
also clear the cache in:
- addEntityClassToList
- removeEntityClassFromList
result after patch:
- fps drop completely eliminated
- same scene stays at ~60 fps
this is not a forge issue, gpu issue, or entity count issue
(images show before and after results, MASSIVE ~75% decrease in render thread)
fixed ver:
EntityColorTint.java
using jurassic-reborn 1.20.1, forge version 47.4.16, java 17.0.8
there is a serious performance issue in net.vit.jurassicreborn.common.util.EntityColorTint.
the method isEntityInList(Entity) is called during entity rendering and performs a linear scan over a class list using Class.isAssignableFrom every call, with no caching.
this runs per-entity, per-frame, on the render thread.
symptoms:
problematic code:
why this is bad:
called repeatedly for the same entity classes
cost scales with entities × frames × class list size
proposed fix (tested):
cache results per entity class and invalidate cache when the list changes
also clear the cache in:
result after patch:
this is not a forge issue, gpu issue, or entity count issue
(images show before and after results, MASSIVE ~75% decrease in render thread)
fixed ver:
EntityColorTint.java