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

Related issues

MC-120508 FPS Drops In Nether MC-141434 Shooting blocks into the nether causes TPS lag MC-143550 Entities moving through portals cause the game to lag MC-148438 Changing Dimensions Causes Server Lag MC-148942 A lot of lag is created when going through dimensions on a server MC-149232 Nether portal lag MC-149908 Placing a villager in a nether portal freezes chunk updates MC-151060 dimention traveling MC-151200 Entering Nether portal lag in a server MC-151729 Creating a Nether portal in the Nether and going thru Times you out. MC-152391 Game freezes, continues to render normally. MC-152466 Nether Portal Lagging server MC-152760 Lag when player cross a nether portal (in server) MC-153060 Traveling nether owerworld server spikes by 100-1000ms MC-153105 Switch Dim's causes Huge lag MC-153556 Dimension MC-154196 Entering a Nether Portal crashes the game MC-154527 Sometimes, Minecraft refuses to load terrain. MC-155707 Stuck in loading terrain screen when going into nether portal MC-156588 Nether Always Stuck On Loading Terrain MC-156973 Infinite Loading Terrain in Nether Portal MC-158070 Game Freezes when Villagers enter a Nether Portal MC-161202 Lagging out of server when going through a Nether Portal. MC-161568 Nether portal makes game freeze MC-165495 When entering or leaving the nether, doors do not work.

Attachments

Comments

migrated
[media][media]
migrated

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

marcono1234

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.

migrated

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.

migrated

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().

migrated

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.

migrated

Traveling through portals overall isn't optimized and it is very laggy / resource hungry sometimes, especially in multiplayer servers.

The whole server notices clearly when any entity teleports through portal, even if the chunks are pre-generated and saved (you've traveled many times before and loaded the terrain around)

This is very big and annoying "leak" / issue, in fact.

I think "some sort of" solution to this can be saving the portals info (The Nether Portal's coordinates to the current chunk/s where the Overworld Portal is and the same thing on the other side). This may be tricky, but it can be twisted / modified in some way so that the bug / issue can be fixed more-reliably.

Irbis

Suggested fix: Store output xyz of nether portal in blocknbt data - like end-gateways. If exit portal block is broken - search for new exit. Lagfriendly - search only for one block most of the time. Also useful for mapmakers and serveradmins - setting output xyz far away with commandblocks.

qwerty23495

Does this still affect the current versions of Minecraft? (1.12.2, 1.13-pre3). If so, please update the ticket accordingly.

migrated

Confirmed for 1.13.1.

Johnibur

Can confirm for 18w44a with even more severe lag than for stable versions.

 

Johnibur

Can confirm for 18w45a too. The server can take several seconds before finding a linked portal, although not sure if it is the cause of global lag or if the lag is caused by the constant busy-waiting CPU load as described in https://bugs.mojang.com/browse/MC-138071.

Johnibur

Still an issue for 18w46a and for 1.14 snapshot this might be related to https://bugs.mojang.com/browse/MC-138114.
Also when mobs are going through any Nether portal it causes https://bugs.mojang.com/browse/MC-138919.

migrated

Can confirm for 18w47a

Johnibur

This issue does not occur when the chunk on the other side of the portal is marked for force loading (and after having actually loaded the force loaded chunk once). Although forceloading is not a solution, but it helps to understand what is going on.

Johnibur

Can confirm for 1.14-pre2.
Here are simple steps on how to reproduce:

  1. Make a superflat world

  2. Create a Nether portal

  3. Go to the Nether, let the chunks generate

  4. Go back, and wait for 1 minute

  5. Now try to go through this portal
    You will notice the tremendous amount of lag, which is only caused by the portal. If I tp to the Nether using /execute in the_nether command, I don't have this issue.
    I followed those steps on a 8x3.5Ghz with 16Gb allocated and made a debug profiling to track the cause of the lag: I joined the whole report but here are the highlights:

    // This is approximately 9.43 ticks per second. It should be 20 ticks per second
    [00] tick - 58.99%/58.99%
    [01] |   connection - 91.24%/53.85%
    [02] |   |   entityBaseTick - 99.59%/53.63%
    [03] |   |   |   portal - 99.97%/53.62%
    [04] |   |   |   |   placing - 99.91%/53.57%
    […]
    [00] nextTickWait - 41.01%/41.01%

    So this means I took some idling time to start/stop the profiler (nextTickWait), and the rest of the time I was stuck in the loading terrain screen. The main consequence of this issue is one player stuck a portal transition will make the server stops ticking for any other player who is playing on the same world at the same time.

Johnibur

Can confirm for 1.14-pre3.

migrated

I was told my ticket (https://bugs.mojang.com/browse/MC-148438) was a duplicate of this one that was created all the way back with version 1.11.2

I play on a lot of servers, this problem is FAR worse in 1.14 snapshots and pre-releases. That's why it took me this long to report it, as I'm used to basic lag when people switch dimensions using a portal. It reduces the TPS quite a bit, but only for 1-2 seconds.

Now in 1.14, it not only drops the TPS, but stops it out right. Now, once a player finishes switching dimensions, everyone else on the server will revert to 2-3 seconds ago, full on rubber banding.  Blocks all get replaced, and players return to the position they were at when the player entering the portal first started switching dimensions. I run a lot of servers, I've never seen anything this bad before.

Johnibur

Can confirm for 1.14-pre4.

[18:40:42] [Server thread/WARN]: Something's taking too long! 'root.tick.connection.entityBaseTick.portal.placing'
Johnibur

Can confirm for 1.14-pre5.
The fix to Nether portals only fixes the transportation of several entities at the same time with the same portal, but a random transportation can still freeze the server for times from 2 to 8 seconds.
The same profiling as described above still applies.

migrated

Video covering this topic:

https://youtu.be/nSRA3fd35og

Irbis

Possible solution: adding blockdata of exit coords to portal blocks. Entering portal block without exit coords or when exit coords are no longer valid (destroyed portal) will cause searching for new exit location. This way only portal changing will cause lags.

 

Another solution: Keeping nether portal block coords similar to POI of villagers - in separate structure. This way only those files need to be checked and searching would be sped up significantly.

Johnibur

Can confirm for 1.14.

migrated

In 1.14, this only appears to happen when entities are going from the nether to the overworld, not the other way around...

Johnibur

@unknown That's probably because the height limit in the Nether is twice less as the Overworld, so the game has to check twice as less blocks for finding portal position. But the lag is present in both ways at a different scale.

migrated

I've been kicked from Realms going both ways through nether portals and it happens around 40-50% of the time.

Johnibur

Can confirm for 1.14.1-pre1.

Johnibur

Can confirm for 1.14.1-pre2.

migrated

Confirmed for 1.14.1

migrated

I can confirm this as well, for 1.14.1. It's bad enough where the lag will cause the server to completely kick everybody until I restart it. 

migrated

Can confirm for 1.14.1. Like someone else said, it's sometimes so bad that the server crashes, with a best case scenario being 5 full seconds of complete suspension of ticks processing. It's gotten to the point where we've written a datapack to automatically warn everyone on the server when someone walks into a portal.

Worth noting that end portals work almost instantly. It's only nether portals that have this lag.

migrated

Not sure if related but we did have a few instances of "extra" portals being generated in the nether. IE a player would go through a existing portal from the over world and a new portal would be generated a block or two away from the existing lit portal. It has happened multiple times with different portals. 

migrated

Able to replicated in 1.14.1

Johnibur

This issue is still present in 1.14.2 pre-release 3, but the time the server stays frozen during portal finding has lowered compared to 1.14.1. Typical duration is now 2-4 seconds per tick. On same host, it was 4-8 seconds before.

migrated

Was able to replicate the bug for 1.14.2 pre-release 3, same issues still occurs but slightly less effective spikes

migrated

Issue is still occurring in public release of 1.14.2 

migrated

Can confirm on 1.14.2.

migrated

Is there a reason this is still unassigned? This is a huge issue for servers. Entering the nether or exiting causes huge lag spikes – upwards of 10 full seconds for my server running on an overclocked 7700K. 

Johnibur

@unknown This is a more complex issue that couldn't be solved by just assigning someone and starting working on an afternoon. Issue is known but involves more than just dealing with Nether portals themselves.

Progress on this issue has already been made on 1.14.2 pre-releases where the cost for loading already generated chunks has been significantly decreased.

migrated

Can confirm on 1.14.3. May be somehow related to MC-149705 ?

z0mbiesrock

Still happens in 1.14.4 except now it permanently deadlocks the entire world in singleplayer and only a force-close can end it.

migrated

Confirmed vanilla 1.14.4

[media]
migrated

Our server has had constant 1-3 second freezes constantly and didn't understand until I tracked it to this issue, it occurs Very often because of zombie pigmen wandering in and out of portals.

migrated

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.)

bdm68

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.

migrated

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

migrated

same thing going on 1.16.1

Irbis

@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.

migrated

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