Skip to content

fix: Prevent world ticking thread hang during ItemEntity#mergeWithNeighbours (#802) - #897

Open
Kameshekf wants to merge 1 commit into
Winds-Studio:ver/1.21.11from
Kameshekf:fix/item-merge-deadlock-802
Open

fix: Prevent world ticking thread hang during ItemEntity#mergeWithNeighbours (#802)#897
Kameshekf wants to merge 1 commit into
Winds-Studio:ver/1.21.11from
Kameshekf:fix/item-merge-deadlock-802

Conversation

@Kameshekf

Copy link
Copy Markdown

Resolves #802

Summary of the Problem

When parallel-world-ticking: enabled: true is active on servers with high-density item drops (such as carpet duper machines, sand duplicators, or high-yield mob farms), ItemEntity#mergeWithNeighbours() causes the Leaf Level Ticking Thread - world to freeze/deadlock in ca.spottedleaf.moonrise.patches.chunk_system.level.entity.ChunkEntitySlices$EntityCollectionBySection.getEntities.

The hang occurred due to two main factors:

  1. Tick Synchronization Spike: Thousands of simultaneously spawned items attempted mergeWithNeighbours() on the exact same tick cycle (this.tickCount % i == 0).
  2. Unbounded Iteration: When massive item piles gather, getEntitiesOfClass() yields an enormous collection of nearby items, leading to excessive lock contention and CPU starvation across parallel world threads.

Solution

  1. Phase-offset merge ticks: Spread item merge checks across ticks using (this.tickCount + this.getId()) % i == 0, eliminating synchronized tick spikes.
  2. Bounded merge iteration: Limit maximum merge attempts to 32 items per entity per merge pass (mergedCount >= 32).

Testing & Verification

  • Tested with 5,000+ duplicated items in a single chunk with parallel-world-ticking: true.
  • Zero thread hangs, zero deadlocks, and watchdog TPS remains completely stable.

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