performance: Improve Activation Range entity iteration
Faster Entity iteration using the chunks full entity list and array access. Faster chunk lookups skipping the cache, as the pattern of access was not suitable for cache usage (each request will likely blow cache) This reduces the cost of Entity Activation Range's initial marking.
This commit is contained in:
parent
bacbd8805f
commit
be7b40634d
2 changed files with 56 additions and 16 deletions
|
@ -46,7 +46,7 @@ index 092bff78ab..a987916055 100644
|
||||||
+ velocitySupport = getBoolean("settings.velocity-support.enabled", false);
|
+ velocitySupport = getBoolean("settings.velocity-support.enabled", false);
|
||||||
+ velocityOnlineMode = getBoolean("settings.velocity-support.online-mode", false);
|
+ velocityOnlineMode = getBoolean("settings.velocity-support.online-mode", false);
|
||||||
+ String secret = getString("settings.velocity-support.secret", "");
|
+ String secret = getString("settings.velocity-support.secret", "");
|
||||||
+ TimingsManager.hiddenConfigs.add("Settings.velocity-support.secret");
|
+ TimingsManager.hiddenConfigs.add("settings.velocity-support.secret");
|
||||||
+ if (velocitySupport && secret.isEmpty()) {
|
+ if (velocitySupport && secret.isEmpty()) {
|
||||||
+ fatal("Velocity support is enabled, but no secret key was specified. A secret key is required!");
|
+ fatal("Velocity support is enabled, but no secret key was specified. A secret key is required!");
|
||||||
+ } else {
|
+ } else {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
From 2e1b3ceece0448dcb8edbe4d2bbd1a30fea0828c Mon Sep 17 00:00:00 2001
|
From 8d53dc5bc54922b59ebfe41f40adbd7a0470787b Mon Sep 17 00:00:00 2001
|
||||||
From: Aikar <aikar@aikar.co>
|
From: Aikar <aikar@aikar.co>
|
||||||
Date: Fri, 13 May 2016 01:38:06 -0400
|
Date: Fri, 13 May 2016 01:38:06 -0400
|
||||||
Subject: [PATCH] Activation Range Improvements
|
Subject: [PATCH] Activation Range Improvements
|
||||||
|
@ -202,18 +202,20 @@ index 5a8c60ad90..29657fed75 100644
|
||||||
return this.c;
|
return this.c;
|
||||||
}
|
}
|
||||||
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
|
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
|
||||||
index 92601c581c..b1cd59b047 100644
|
index 92601c581c..ecafbaa6bf 100644
|
||||||
--- a/src/main/java/org/spigotmc/ActivationRange.java
|
--- a/src/main/java/org/spigotmc/ActivationRange.java
|
||||||
+++ b/src/main/java/org/spigotmc/ActivationRange.java
|
+++ b/src/main/java/org/spigotmc/ActivationRange.java
|
||||||
@@ -3,6 +3,7 @@ package org.spigotmc;
|
@@ -3,7 +3,9 @@ package org.spigotmc;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.minecraft.server.AxisAlignedBB;
|
import net.minecraft.server.AxisAlignedBB;
|
||||||
+import net.minecraft.server.BehaviorController;
|
+import net.minecraft.server.BehaviorController;
|
||||||
import net.minecraft.server.Chunk;
|
import net.minecraft.server.Chunk;
|
||||||
|
+import net.minecraft.server.ChunkProviderServer; // Paper
|
||||||
import net.minecraft.server.Entity;
|
import net.minecraft.server.Entity;
|
||||||
import net.minecraft.server.EntityAmbient;
|
import net.minecraft.server.EntityAmbient;
|
||||||
@@ -16,10 +17,12 @@ import net.minecraft.server.EntityEnderDragon;
|
import net.minecraft.server.EntityAnimal;
|
||||||
|
@@ -16,10 +18,12 @@ import net.minecraft.server.EntityEnderDragon;
|
||||||
import net.minecraft.server.EntityFallingBlock; // Paper
|
import net.minecraft.server.EntityFallingBlock; // Paper
|
||||||
import net.minecraft.server.EntityFireball;
|
import net.minecraft.server.EntityFireball;
|
||||||
import net.minecraft.server.EntityFireworks;
|
import net.minecraft.server.EntityFireworks;
|
||||||
|
@ -226,7 +228,7 @@ index 92601c581c..b1cd59b047 100644
|
||||||
import net.minecraft.server.EntityProjectile;
|
import net.minecraft.server.EntityProjectile;
|
||||||
import net.minecraft.server.EntityRaider;
|
import net.minecraft.server.EntityRaider;
|
||||||
import net.minecraft.server.EntitySheep;
|
import net.minecraft.server.EntitySheep;
|
||||||
@@ -30,15 +33,22 @@ import net.minecraft.server.EntityThrownTrident;
|
@@ -30,15 +34,22 @@ import net.minecraft.server.EntityThrownTrident;
|
||||||
import net.minecraft.server.EntityVillager;
|
import net.minecraft.server.EntityVillager;
|
||||||
import net.minecraft.server.EntityWither;
|
import net.minecraft.server.EntityWither;
|
||||||
import net.minecraft.server.MathHelper;
|
import net.minecraft.server.MathHelper;
|
||||||
|
@ -249,7 +251,7 @@ index 92601c581c..b1cd59b047 100644
|
||||||
MONSTER,
|
MONSTER,
|
||||||
ANIMAL,
|
ANIMAL,
|
||||||
RAIDER,
|
RAIDER,
|
||||||
@@ -58,6 +68,7 @@ public class ActivationRange
|
@@ -58,6 +69,7 @@ public class ActivationRange
|
||||||
*/
|
*/
|
||||||
public static ActivationType initializeEntityActivationType(Entity entity)
|
public static ActivationType initializeEntityActivationType(Entity entity)
|
||||||
{
|
{
|
||||||
|
@ -257,7 +259,7 @@ index 92601c581c..b1cd59b047 100644
|
||||||
if ( entity instanceof EntityRaider )
|
if ( entity instanceof EntityRaider )
|
||||||
{
|
{
|
||||||
return ActivationType.RAIDER;
|
return ActivationType.RAIDER;
|
||||||
@@ -86,6 +97,7 @@ public class ActivationRange
|
@@ -86,6 +98,7 @@ public class ActivationRange
|
||||||
|| ( entity.activationType == ActivationType.RAIDER && config.raiderActivationRange == 0 )
|
|| ( entity.activationType == ActivationType.RAIDER && config.raiderActivationRange == 0 )
|
||||||
|| ( entity.activationType == ActivationType.ANIMAL && config.animalActivationRange == 0 )
|
|| ( entity.activationType == ActivationType.ANIMAL && config.animalActivationRange == 0 )
|
||||||
|| ( entity.activationType == ActivationType.MONSTER && config.monsterActivationRange == 0 )
|
|| ( entity.activationType == ActivationType.MONSTER && config.monsterActivationRange == 0 )
|
||||||
|
@ -265,15 +267,16 @@ index 92601c581c..b1cd59b047 100644
|
||||||
|| entity instanceof EntityHuman
|
|| entity instanceof EntityHuman
|
||||||
|| entity instanceof EntityProjectile
|
|| entity instanceof EntityProjectile
|
||||||
|| entity instanceof EntityEnderDragon
|
|| entity instanceof EntityEnderDragon
|
||||||
@@ -118,6 +130,7 @@ public class ActivationRange
|
@@ -118,6 +131,8 @@ public class ActivationRange
|
||||||
final int raiderActivationRange = world.spigotConfig.raiderActivationRange;
|
final int raiderActivationRange = world.spigotConfig.raiderActivationRange;
|
||||||
final int animalActivationRange = world.spigotConfig.animalActivationRange;
|
final int animalActivationRange = world.spigotConfig.animalActivationRange;
|
||||||
final int monsterActivationRange = world.spigotConfig.monsterActivationRange;
|
final int monsterActivationRange = world.spigotConfig.monsterActivationRange;
|
||||||
+ final int waterActivationRange = world.spigotConfig.waterActivationRange; // Paper
|
+ final int waterActivationRange = world.spigotConfig.waterActivationRange; // Paper
|
||||||
|
+ final ChunkProviderServer chunkProvider = (ChunkProviderServer) world.getChunkProvider(); // Paper
|
||||||
|
|
||||||
int maxRange = Math.max( monsterActivationRange, animalActivationRange );
|
int maxRange = Math.max( monsterActivationRange, animalActivationRange );
|
||||||
maxRange = Math.max( maxRange, raiderActivationRange );
|
maxRange = Math.max( maxRange, raiderActivationRange );
|
||||||
@@ -133,6 +146,8 @@ public class ActivationRange
|
@@ -133,6 +148,8 @@ public class ActivationRange
|
||||||
ActivationType.RAIDER.boundingBox = player.getBoundingBox().grow( raiderActivationRange, 256, raiderActivationRange );
|
ActivationType.RAIDER.boundingBox = player.getBoundingBox().grow( raiderActivationRange, 256, raiderActivationRange );
|
||||||
ActivationType.ANIMAL.boundingBox = player.getBoundingBox().grow( animalActivationRange, 256, animalActivationRange );
|
ActivationType.ANIMAL.boundingBox = player.getBoundingBox().grow( animalActivationRange, 256, animalActivationRange );
|
||||||
ActivationType.MONSTER.boundingBox = player.getBoundingBox().grow( monsterActivationRange, 256, monsterActivationRange );
|
ActivationType.MONSTER.boundingBox = player.getBoundingBox().grow( monsterActivationRange, 256, monsterActivationRange );
|
||||||
|
@ -282,7 +285,44 @@ index 92601c581c..b1cd59b047 100644
|
||||||
|
|
||||||
int i = MathHelper.floor( maxBB.minX / 16.0D );
|
int i = MathHelper.floor( maxBB.minX / 16.0D );
|
||||||
int j = MathHelper.floor( maxBB.maxX / 16.0D );
|
int j = MathHelper.floor( maxBB.maxX / 16.0D );
|
||||||
@@ -188,22 +203,22 @@ public class ActivationRange
|
@@ -143,7 +160,7 @@ public class ActivationRange
|
||||||
|
{
|
||||||
|
for ( int j1 = k; j1 <= l; ++j1 )
|
||||||
|
{
|
||||||
|
- Chunk chunk = (Chunk) world.getChunkIfLoadedImmediately( i1, j1 );
|
||||||
|
+ Chunk chunk = chunkProvider.getChunkAtIfLoadedMainThreadNoCache( i1, j1 ); // Paper
|
||||||
|
if ( chunk != null )
|
||||||
|
{
|
||||||
|
activateChunkEntities( chunk );
|
||||||
|
@@ -161,19 +178,15 @@ public class ActivationRange
|
||||||
|
*/
|
||||||
|
private static void activateChunkEntities(Chunk chunk)
|
||||||
|
{
|
||||||
|
- for ( List<Entity> slice : chunk.entitySlices )
|
||||||
|
- {
|
||||||
|
- for ( Entity entity : (Collection<Entity>) slice )
|
||||||
|
+ // Paper start
|
||||||
|
+ Entity[] rawData = chunk.entities.getRawData();
|
||||||
|
+ for (int i = 0; i < chunk.entities.size(); i++) {
|
||||||
|
+ Entity entity = rawData[i];
|
||||||
|
+ //for ( Entity entity : (Collection<Entity>) slice )
|
||||||
|
+ // Paper end
|
||||||
|
{
|
||||||
|
- if ( MinecraftServer.currentTick > entity.activatedTick )
|
||||||
|
- {
|
||||||
|
- if ( entity.defaultActivationState )
|
||||||
|
- {
|
||||||
|
- entity.activatedTick = MinecraftServer.currentTick;
|
||||||
|
- continue;
|
||||||
|
- }
|
||||||
|
- if ( entity.activationType.boundingBox.c( entity.getBoundingBox() ) )
|
||||||
|
- {
|
||||||
|
+ if (MinecraftServer.currentTick > entity.activatedTick) {
|
||||||
|
+ if (entity.defaultActivationState || entity.activationType.boundingBox.c(entity.getBoundingBox())) { // Paper
|
||||||
|
entity.activatedTick = MinecraftServer.currentTick;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -188,22 +201,22 @@ public class ActivationRange
|
||||||
* @param entity
|
* @param entity
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -311,7 +351,7 @@ index 92601c581c..b1cd59b047 100644
|
||||||
}
|
}
|
||||||
// special cases.
|
// special cases.
|
||||||
if ( entity instanceof EntityLiving )
|
if ( entity instanceof EntityLiving )
|
||||||
@@ -211,33 +226,49 @@ public class ActivationRange
|
@@ -211,33 +224,49 @@ public class ActivationRange
|
||||||
EntityLiving living = (EntityLiving) entity;
|
EntityLiving living = (EntityLiving) entity;
|
||||||
if ( /*TODO: Missed mapping? living.attackTicks > 0 || */ living.hurtTicks > 0 || living.effects.size() > 0 )
|
if ( /*TODO: Missed mapping? living.attackTicks > 0 || */ living.hurtTicks > 0 || living.effects.size() > 0 )
|
||||||
{
|
{
|
||||||
|
@ -357,11 +397,11 @@ index 92601c581c..b1cd59b047 100644
|
||||||
if (entity instanceof EntityCreeper && ((EntityCreeper) entity).isIgnited()) { // isExplosive
|
if (entity instanceof EntityCreeper && ((EntityCreeper) entity).isIgnited()) { // isExplosive
|
||||||
- return true;
|
- return true;
|
||||||
+ return 20; // Paper
|
+ return 20; // Paper
|
||||||
+ }
|
}
|
||||||
+ // Paper start
|
+ // Paper start
|
||||||
+ if (entity instanceof EntityInsentient && ((EntityInsentient) entity).targetSelector.hasTasks() ) {
|
+ if (entity instanceof EntityInsentient && ((EntityInsentient) entity).targetSelector.hasTasks() ) {
|
||||||
+ return 0;
|
+ return 0;
|
||||||
}
|
+ }
|
||||||
+ // Paper end
|
+ // Paper end
|
||||||
}
|
}
|
||||||
- return false;
|
- return false;
|
||||||
|
@ -369,7 +409,7 @@ index 92601c581c..b1cd59b047 100644
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -254,6 +285,7 @@ public class ActivationRange
|
@@ -254,6 +283,7 @@ public class ActivationRange
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isActive = entity.activatedTick >= MinecraftServer.currentTick || entity.defaultActivationState;
|
boolean isActive = entity.activatedTick >= MinecraftServer.currentTick || entity.defaultActivationState;
|
||||||
|
@ -377,7 +417,7 @@ index 92601c581c..b1cd59b047 100644
|
||||||
|
|
||||||
// Should this entity tick?
|
// Should this entity tick?
|
||||||
if ( !isActive )
|
if ( !isActive )
|
||||||
@@ -261,15 +293,19 @@ public class ActivationRange
|
@@ -261,15 +291,19 @@ public class ActivationRange
|
||||||
if ( ( MinecraftServer.currentTick - entity.activatedTick - 1 ) % 20 == 0 )
|
if ( ( MinecraftServer.currentTick - entity.activatedTick - 1 ) % 20 == 0 )
|
||||||
{
|
{
|
||||||
// Check immunities every 20 ticks.
|
// Check immunities every 20 ticks.
|
||||||
|
|
Loading…
Reference in a new issue