9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2026-01-06 15:51:31 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0081-Increase-time-statistics-in-intervals.patch
Dreeam 9a4efaa230 Drop patch that causes performance regression
Originally vanilla logic is to use stream, and Mojang switched it to Guava's Collections2
since 1.21.4. It is much faster than using stream or manually adding to a new ArrayList.
Manually adding to a new ArrayList requires allocating a new object array. However, the Collections2
lazy handles filter condition on iteration, so much better.
2025-08-04 19:25:56 +08:00

88 lines
5.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 30 Nov 2022 22:50:57 +0100
Subject: [PATCH] Increase time statistics in intervals
License: MIT (https://opensource.org/licenses/MIT)
Gale - https://galemc.org
This patch is based on the following patch:
"Smarter statistics ticking"
By: Mykyta Komarnytskyy <nkomarn@hotmail.com>
As part of: Hydrinity (https://github.com/duplexsystem/Hydrinity)
Licensed under: MIT (https://opensource.org/licenses/MIT)
* Hydrinity description *
In vanilla, statistics that count time spent for an action (i.e. time played or sneak time) are incremented every tick. This is retarded. With this patch and a configured interval of 20, the statistics are only ticked every 20th tick and are incremented by 20 ticks at a time. This means a lot less ticking with the same accurate counting.
With an interval of 20, this patch saves roughly 3ms per tick on a server w/ 80 players online.
* Hydrinity copyright *
This patch was created for the Hydrinity project <https://github.com/Hydrinity/Hydrinity> by Mykyta Komarnytskyy <nkomarn@hotmail.com> under the MIT license.
MIT License
Copyright (c) 2020 Mykyta Komarnytskyy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
diff --git a/net/minecraft/world/entity/player/Player.java b/net/minecraft/world/entity/player/Player.java
index 6207ffb19f8d98ea6496e4d80495bf590b1be7ca..76b35938176a592beb8d490e11cf9970e5d09405 100644
--- a/net/minecraft/world/entity/player/Player.java
+++ b/net/minecraft/world/entity/player/Player.java
@@ -166,6 +166,7 @@ public abstract class Player extends LivingEntity {
protected static final EntityDataAccessor<Byte> DATA_PLAYER_MAIN_HAND = SynchedEntityData.defineId(Player.class, EntityDataSerializers.BYTE);
protected static final EntityDataAccessor<CompoundTag> DATA_SHOULDER_LEFT = SynchedEntityData.defineId(Player.class, EntityDataSerializers.COMPOUND_TAG);
protected static final EntityDataAccessor<CompoundTag> DATA_SHOULDER_RIGHT = SynchedEntityData.defineId(Player.class, EntityDataSerializers.COMPOUND_TAG);
+ public static int increaseTimeStatisticsInterval; // Gale - Hydrinity - increase time statistics in intervals - store as static field for fast access
public static final int CLIENT_LOADED_TIMEOUT_TIME = 60;
private static final short DEFAULT_SLEEP_TIMER = 0;
private static final float DEFAULT_EXPERIENCE_PROGRESS = 0.0F;
@@ -332,19 +333,23 @@ public abstract class Player extends LivingEntity {
this.moveCloak();
if (this instanceof ServerPlayer serverPlayer) {
this.foodData.tick(serverPlayer);
- this.awardStat(Stats.PLAY_TIME);
- this.awardStat(Stats.TOTAL_WORLD_TIME);
+ // Gale start - Hydrinity - increase time statistics in intervals
+ if (increaseTimeStatisticsInterval == 1 || this.tickCount % increaseTimeStatisticsInterval == 0) {
+ this.awardStat(Stats.PLAY_TIME, increaseTimeStatisticsInterval);
+ this.awardStat(Stats.TOTAL_WORLD_TIME, increaseTimeStatisticsInterval);
+ // Gale end - Hydrinity - increase time statistics in intervals
if (this.isAlive()) {
- this.awardStat(Stats.TIME_SINCE_DEATH);
+ this.awardStat(Stats.TIME_SINCE_DEATH, increaseTimeStatisticsInterval); // Gale - Hydrinity - increase time statistics in intervals
}
if (this.isDiscrete()) {
- this.awardStat(Stats.CROUCH_TIME);
+ this.awardStat(Stats.CROUCH_TIME, increaseTimeStatisticsInterval); // Gale - Hydrinity - increase time statistics in intervals
}
if (!this.isSleeping()) {
- this.awardStat(Stats.TIME_SINCE_REST);
+ this.awardStat(Stats.TIME_SINCE_REST, increaseTimeStatisticsInterval); // Gale - Hydrinity - increase time statistics in intervals
}
+ } // Gale - Hydrinity - increase time statistics in intervals
}
int i = 29999999;