-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache tracking range type enum ordinal
Yes, I was shocked, flabbergasted even, when I found out that "Enum.ordinal()" was lagging here But I guess it makes sense: It is a function that is called every tick for each entity, and it is a bit wasteful converting from enum to ordinal every time
- Loading branch information
1 parent
d03d4b9
commit 53dcccb
Showing
4 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
patches/server/0014-Cache-tracking-range-type-enum-ordinal.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: MrPowerGamerBR <git@mrpowergamerbr.com> | ||
Date: Wed, 22 Nov 2023 01:44:52 -0300 | ||
Subject: [PATCH] Cache tracking range type enum ordinal | ||
|
||
Yes, I was shocked, flabbergasted even, when I found out that "Enum.ordinal()" was lagging here | ||
|
||
But I guess it makes sense: It is a function that is called every tick for each entity, and it is a bit wasteful converting from enum to ordinal every time | ||
|
||
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java | ||
index e544081e8214802facb77defc1e9aa765834be2a..6d9aa481cf0a3c31505977b98ca5f2a6b812a757 100644 | ||
--- a/src/main/java/net/minecraft/world/entity/Entity.java | ||
+++ b/src/main/java/net/minecraft/world/entity/Entity.java | ||
@@ -501,6 +501,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource { | ||
// Paper end | ||
// Paper start - optimise entity tracking | ||
final org.spigotmc.TrackingRange.TrackingRangeType trackingRangeType = org.spigotmc.TrackingRange.getTrackingRangeType(this); | ||
+ final int trackingRangeTypeOrdinal = trackingRangeType.ordinal(); // SparklyPaper - cache tracking range type enum ordinal | ||
// Paper start - make end portalling safe | ||
public BlockPos portalBlock; | ||
public ServerLevel portalWorld; | ||
@@ -541,24 +542,26 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource { | ||
public final com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> getPlayersInTrackRange() { | ||
// determine highest range of passengers | ||
if (this.passengers.isEmpty()) { | ||
- return ((ServerLevel)this.level).getChunkSource().chunkMap.playerEntityTrackerTrackMaps[this.trackingRangeType.ordinal()] | ||
+ return ((ServerLevel)this.level).getChunkSource().chunkMap.playerEntityTrackerTrackMaps[this.trackingRangeTypeOrdinal] // SparklyPaper - cache tracking range type enum ordinal | ||
.getObjectsInRange(MCUtil.getCoordinateKey(this)); | ||
} | ||
Iterable<Entity> passengers = this.getIndirectPassengers(); | ||
net.minecraft.server.level.ChunkMap chunkMap = ((ServerLevel)this.level).getChunkSource().chunkMap; | ||
- org.spigotmc.TrackingRange.TrackingRangeType type = this.trackingRangeType; | ||
- int range = chunkMap.getEntityTrackerRange(type.ordinal()); | ||
+ int typeOrdinal = this.trackingRangeTypeOrdinal; // SparklyPaper - cache tracking range type enum ordinal | ||
+ int range = chunkMap.getEntityTrackerRange(typeOrdinal); // SparklyPaper - cache tracking range type enum ordinal | ||
|
||
for (Entity passenger : passengers) { | ||
- org.spigotmc.TrackingRange.TrackingRangeType passengerType = passenger.trackingRangeType; | ||
- int passengerRange = chunkMap.getEntityTrackerRange(passengerType.ordinal()); | ||
+ // SparklyPaper start - cache tracking range type enum ordinal | ||
+ int passengerTypeOrdinal = passenger.trackingRangeTypeOrdinal; | ||
+ int passengerRange = chunkMap.getEntityTrackerRange(passengerTypeOrdinal); | ||
if (passengerRange > range) { | ||
- type = passengerType; | ||
+ typeOrdinal = passengerTypeOrdinal; // SparklyPaper - cache tracking range type enum ordinal | ||
range = passengerRange; | ||
} | ||
+ // SparklyPaper end | ||
} | ||
|
||
- return chunkMap.playerEntityTrackerTrackMaps[type.ordinal()].getObjectsInRange(MCUtil.getCoordinateKey(this)); | ||
+ return chunkMap.playerEntityTrackerTrackMaps[typeOrdinal].getObjectsInRange(MCUtil.getCoordinateKey(this)); // SparklyPaper - cache tracking range type enum ordinal | ||
} | ||
// Paper end - optimise entity tracking | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters