Skip to content

[Overhauled] Improve scrubber efficiency calculation - #866

Open
Meldexun wants to merge 1 commit into
tomdodd4598:1.12.2ofrom
Meldexun:overhauled-improve-scrubber-efficiency-calculation
Open

[Overhauled] Improve scrubber efficiency calculation#866
Meldexun wants to merge 1 commit into
tomdodd4598:1.12.2ofrom
Meldexun:overhauled-improve-scrubber-efficiency-calculation

Conversation

@Meldexun

Copy link
Copy Markdown

This PR reimplements how scrubbers calculate their efficiency to fix issues, improve performance, and reduce unnecessary complexity.

Memory Leak: We noticed a memory leak in RLCraft Dregora 1.1.2b which uses NuclearCraft 2.19a. This was the initial motivation to look into the whole thing.
The problem is that RadiationEnvironmentHandler.removeTile is only called in TileEntity.invalidate which is only called when the tile entity gets removed directly (for example by breaking the block) but not when the chunk is unloaded and also not when the world is unloaded. This causes server world instances to be strongly referenced by RadiationEnvironmentHandler.ENVIRONMENT_MAP forever.

Looking into the RadiationEnvironmentHandler implementation I noticed that it's very convoluted. From my understanding the only goal of the RadiationEnvironmentHandler is to efficiently compute the Map<BlockPos, Integer> occlusion maps of the scrubbers.

I simplified the whole thing by just using a Object2IntMap<BlockPos> for every dimension stored in a WeakHashMap<World, ...>.

On load a scrubber increments the counter at every position that it affects. When a scrubber is unloaded (onChunkUnload) or removed (invalidate) the counters are decreased again and when reaching zero the entries are removed.
These per-world occlusion maps can then simply be used directly in RadiationEnvironmentHandler.checkRadiationEnvironmentInfo.

This prevents memory leaks because it never holds a strong reference to any world object.

I expect performance to be similar to the old implementation because

  • There is no longer a world tick event listener that constantly removes and adds elements from queues, sets and maps
  • Avoid auto-boxing by using Object2IntOpenHashMap
  • checkRadiationEnvironmentInfo now always checks every affected position, while previously non-occlusive positions where not processed until they where re-added to the occlusion map by checkRadiationEnvironmentInfo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant