mojira.dev
MC-117914

Entities crossing dimensions through nether portal causes tremendous lag

The bug

Every time somebody goes through a nether portal or an entity is sent to another dimension the whole server freezes for 1-2 seconds. The search algorithm for portals seems to be really inefficient.

How to reproduce

Video demonstrating the issue: https://gfycat.com/FriendlyInfiniteGreyhounddog

Linked issues

MC-120508 FPS Drops In Nether Resolved MC-141434 Shooting blocks into the nether causes TPS lag Resolved MC-143550 Entities moving through portals cause the game to lag Resolved MC-148438 Changing Dimensions Causes Server Lag Resolved MC-148942 A lot of lag is created when going through dimensions on a server Resolved

Attachments

Comments 47

casually going with my llama caravan trough a portal from the nether to the overworld already lags my singleplayer pretty hard 😞

Could be partwise caused by MC-116279. Is there a portal in the overworld at the corresponding position?

Additionally the fact that portal entries are removed from the cached portal position map after not being used for 300 ticks (if world time % 100 == 0) is probably not beneficial at all.

There was a portal on the overworld side. We notice it all the time during normal gameplay. Somebody goes through a portal -> lag spike for 1-2 seconds.

Nicklas Ekstrand

This is a really terrible performance issue. I really hope there will be a fix soon.

If I understand it correctly the main issue is when going from the nether to the overworld.
1) The caching of portal positions that are done uses the destination coordinates as key for the cache. But since the floating point values from the nether position is multiplied with 8, the resulting destination may be 8 different value in the overworld from each portal block in the nether. The cache values are deleted after 300-400 ticks if not reused. My suggestion: the cache key needs to be based on the portal block that is entered rather than the destination. Increase cache time by a factor of 2 or 3, or only update the cache when portals are created/destroyed.
2) When there is no cache hit, a full search is performed from -128 to +128 on both x and z axis and the full height of the world. That is a lot of blocks to scan for a portal. My suggestion is to improve the scanning by searching in order of distance to the center point. Once a portal block has been found, the search can be terminated and thus not all blocks needs to be scanned.

If you look into the code via MCP, the relevant class is net.minecraft.world.Teleporter and methods placeInExistingPortal() and removeStalePortalLocations().

Nicklaus Ekstrand is right, I think. But there is my solution:
1) Cache the coordinates of destination portal as long as chunk is loaded. This will already resolve laggy portal issues.
2) Search for nether portal blocks in order of distance. This can be made by first looking in chunk where estimated point is and loading more chunks if needed. This will lower initial lag.
3) Clear cache of neighbor portals at destination dimension when new portal is created/destroyed at source dimension. This will resolve leftover issues.

37 more comments

Isn't there the possibility to keep a global (or region file based) record of portal blocks? Then, portals only need to check for the positions in that list instead of searching through millions of blocks. Portals are pretty rare blocks, so that list doesn't even need to be that large. That should be way more efficient than searching for essentially a needle in a haystack.

(I understand that it would be very hard to "upgrade" existing worlds to this feature, but I guess it could improve portal performance by a lot.)

As of 1.14.x, this issue appears to have two distinct causes: (1) Slow search algorithm for portals, and (2) Slow loading of Nether chunks. Fixing both causes is needed to restore good performance.

In 1.14 I can´t cross de nether portal because the "Loading Terrain" screen is infnite

same thing going on 1.16.1

@Max, please make a new bugreport for your problem with portals, as this bug was resolved almost a year ago and I can still confirm it being fixed. Also try to add your bug reproduction steps if you can.

ilmango

boq

Confirmed

Very Important

Chunk loading, Performance

dimension, entity, nether, nether_portal

Minecraft 1.11.2, Minecraft 1.12 Pre-Release 5, Minecraft 1.12.1, Minecraft 1.13.1, Minecraft 1.13.2, ..., Minecraft 1.14.1, Minecraft 1.14.2 Pre-Release 3, Minecraft 1.14.2, Minecraft 1.14.3, 1.14.4

19w36a

Retrieved