Vampirism - Become a vampire!

Vampirism - Become a vampire!

16M Downloads

ReflectionHelper lag

LemADEC opened this issue ยท 2 comments

commented

ReflectionHelper is intended for one time use, typically at boot. It appears the mod is using it every tick for vampires, this is causing lag due to the constant lookup in the (de)obfuscation tables.
Instead, you can cache the property accessor and directly reuse it, saving a lot of CPU time.

Profiler shows up notably here:

e = ReflectionHelper.getPrivateValue(FoodStats.class, foodStats, "foodExhaustionLevel", SRGNAMES.FoodStats_foodExhaustionLevel);

I wouldn't be surprise to see here too:

avoidSun = ReflectionHelper.getPrivateValue(PathNavigateGround.class, (PathNavigateGround) attacker.getNavigator(), "shouldAvoidSun", SRGNAMES.PathNavigateGround_shouldAvoidSun);

commented

Oh, thanks for reporting this. I did not think it would cause a noticeable amount of lag.
I planned to use AccessTransformers to avoid having to use Reflection, but there always was a severe problem with that when I tried to do so, not sure what it was though.
But caching the accessor sounds like a good idea, I will try to implement that.

Thank you very much for investigating this issue and your suggestion.

commented

Caching the fields did help to improve the performance a little bit.
In my test scenario it got the blood update tick time down from 0.11% to 0.05% (with one player).
Using ATs to avoid Reflection completely would get it down to about 0.03%.
Same goes for the EntityAttackSunNoMelee.

Maybe I will give ATs another try in 1.11. #154