2020-05-06 09:48:49 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2018-11-03 03:14:53 +00:00
From: Aikar <aikar@aikar.co>
Date: Fri, 2 Nov 2018 23:11:51 -0400
Subject: [PATCH] Optimize World Time Updates
Splits time updates into incremental updates as well as does
the updates per world, so that we can re-use the same packet
object for every player unless they have per-player time enabled.
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2020-05-06 09:48:49 +00:00
index c97bbe933dd05829d9da7bc71d03d2c0a26a4ad1..3d9cc2ce67b5dc033df397e8d1c31f718792dcc4 100644
2018-11-03 03:14:53 +00:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
Improve mid tick chunk loading, Fix Oversleep, other improvements
Process loads outside of any canSleep check. Original intent was to
only apply those restrictions to generations but realized I had some
checks higher up the call chain.
Reworked the back off strategy to just run every 1 millisecond per world,
and to apply the per tick limit to generations only.
This guarantees that your chunk will load with at most around 1ms delay.
Additionally, fire midTick processing in a few more places, notably the
oversleep section so we can keep processing loads here too which has
a large up to 50ms window...
Speaking of oversleep, we had a bug in our implementation changes for
Timings that caused oversleep to not sleep the correct amount.
Because we now moved it into the NEXT tick instead of THIS tick, the
value of nextTick had already been increased to +50ms, resulting in
the risk of sleeping more than it should, but, more importantly, this
caused every task that was trying to NOT run during oversleep to actually
run during oversleep.
This is now fixed.
Another small tweak is to the /tps command, to no longer show the star when
TPS is right at 20.
Due to ineffeciencies in the sleep precision, TPS is commonly 20.02.
This causes the star to show up almost constantly, so now only show it if
we actually hit a real "catchup".
This commit also improves the changes to the CallbackExecutor, in that
it now is also recursion safe.
It was possible that the executor could run tasks out of desired order
if the executor task scheduled more executor tasks.
We solve this by ensuring new additions do not enter the currently iterated queue.
Each depth level will have its own queue.
Fixes #3220
2020-04-26 03:47:29 +00:00
@@ -1166,12 +1166,24 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2018-11-03 03:14:53 +00:00
2019-05-05 11:12:32 +00:00
MinecraftTimings.timeUpdateTimer.startTiming(); // Spigot // Paper
2018-11-03 03:14:53 +00:00
// Send time updates to everyone, it will get the right time from the world the player is in.
- if (this.ticks % 20 == 0) {
- for (int i = 0; i < this.getPlayerList().players.size(); ++i) {
- EntityPlayer entityplayer = (EntityPlayer) this.getPlayerList().players.get(i);
2019-06-25 01:47:58 +00:00
- entityplayer.playerConnection.sendPacket(new PacketPlayOutUpdateTime(entityplayer.world.getTime(), entityplayer.getPlayerTime(), entityplayer.world.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE))); // Add support for per player time
2018-11-03 03:14:53 +00:00
+ // Paper start - optimize time updates
+ for (final WorldServer world : this.getWorlds()) {
2019-06-25 01:47:58 +00:00
+ final boolean doDaylight = world.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE);
2018-11-03 03:14:53 +00:00
+ final long dayTime = world.getDayTime();
+ long worldTime = world.getTime();
+ final PacketPlayOutUpdateTime worldPacket = new PacketPlayOutUpdateTime(worldTime, dayTime, doDaylight);
2019-05-05 11:12:32 +00:00
+ for (EntityHuman entityhuman : world.getPlayers()) {
2018-11-03 03:14:53 +00:00
+ if (!(entityhuman instanceof EntityPlayer) || (ticks + entityhuman.getId()) % 20 != 0) {
+ continue;
+ }
+ EntityPlayer entityplayer = (EntityPlayer) entityhuman;
+ long playerTime = entityplayer.getPlayerTime();
+ PacketPlayOutUpdateTime packet = (playerTime == dayTime) ? worldPacket :
+ new PacketPlayOutUpdateTime(worldTime, playerTime, doDaylight);
+ entityplayer.playerConnection.sendPacket(packet); // Add support for per player time
}
}
+ // Paper end
2019-05-05 11:12:32 +00:00
MinecraftTimings.timeUpdateTimer.stopTiming(); // Spigot // Paper
2018-11-03 03:14:53 +00:00
2019-06-25 01:47:58 +00:00
while (iterator.hasNext()) {