Paper/Spigot-Server-Patches/0069-Use-a-Shared-Random-for-Entities.patch
Aikar 6fda3fd0ed
(FINAL 1.16.2) Improve Timings support for Active vs Inactive vs Passengers
This makes it so entities that are passengers of other entities no longer count in the parents timings, as well as
tracks them as a separate timers per their tick status.

This lets you see how much time is spent in activated entities vs inactive (as inactive still has to do work)

Passengers is also tracked separately so you can identify "Villagers in Minecarts" vs roaming villagers, as
the lack of ability to move can impact their performance characteristics.

This will likely break any plugin that was naughty and directly messed with our internal timings as this
moves the timings to the EntityTypes object, speeding up creation of Entities to no longer store
a timing handler object per entity.

This will also change the output of the entities in timings to use internal ID's instead of class names.

If a plugin is broken by this, shame them for doing bad things. Paper will not fix it, they will have to fix it.
2020-09-10 19:08:02 -04:00

43 lines
1.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 22 Mar 2016 00:33:47 -0400
Subject: [PATCH] Use a Shared Random for Entities
Reduces memory usage and provides ensures more randomness, Especially since a lot of garbage entity objects get created.
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index fd881f2e262f5514392a484cf3e442173acb9be1..f74eaf5cfd0add930d71d89e9a5441f4115e5f6c 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -58,6 +58,21 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
return tag.hasKey("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level;
}
+ // Paper start
+ public static Random SHARED_RANDOM = new Random() {
+ private boolean locked = false;
+ @Override
+ public synchronized void setSeed(long seed) {
+ if (locked) {
+ LogManager.getLogger().error("Ignoring setSeed on Entity.SHARED_RANDOM", new Throwable());
+ } else {
+ super.setSeed(seed);
+ locked = true;
+ }
+ }
+ };
+ // Paper end
+
private CraftEntity bukkitEntity;
public CraftEntity getBukkitEntity() {
@@ -186,7 +201,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
this.x = Vec3D.a;
this.am = 1.0F;
this.an = 1.0F;
- this.random = new Random();
+ this.random = SHARED_RANDOM; // Paper
this.fireTicks = -this.getMaxFireTicks();
this.M = new Object2DoubleArrayMap(2);
this.justCreated = true;