Botania

Botania

133M Downloads

Idle mana spreader has high processing time usage

TheRealWormbo opened this issue · 0 comments

commented

Version Information

Forge version: 14.23.5.2847
Botania version: r1.10-363 (but relevant code has not changed since then)

Further Information

(The issue is best visualized using a tool like LagGoggles.)
Steps to reproduce:

  1. Set up four mana spreaders with the four possible combinations of empty and full mana sources and mana sinks. (e.g. empty mana pool as empty source/sink, everlasting guilty pool as full source/sink)
  2. Profile each mana spreader's processing time (e.g. with aforementioned LagGoggles tool)

What I expected to happen:
Idle mana spreaders should not have a higher individual processing time than active mana spreaders and the reason for it being idle should not have a large impact on the processing time.

What happened instead:
An idle mana spreader aimed at a mana sink that is not full has a higher average processing time than an active mana spreader, or an idle mana spreader aimed at a full mana sink. (data from several measurements: target full – 2-8µs/t, target not full/idle – 48-57µs/t, target not full/active – 32-35µs/t)

Potentially relevant code location: class vazkii.botania.common.block.tile.mana.TileSpreader, method getBurst()
A separate profiling using CPU sampling in an external Java profiling tool (VisualVM) suggests that this method is called very frequently on idle spreaders if their target mana sink is not full. Apparently creating the mana burst entity is an expensive operation that is performed even if subsequently that entity is not required because the spreader does not have enough mana to actually fire the mana burst. Considering that an overwhelming part of getBurst()'s execution time (roughly 80%) is spent in the EntityManaBurst constructor, it might be worth investigating whether the subsequent checks that may result in that entity not being used could be made before creating the entity in the first place.