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:
Spottedleaf 2020-03-29 22:41:33 -04:00 committed by Aikar
parent bacbd8805f
commit be7b40634d
No known key found for this signature in database
GPG key ID: 401ADFC9891FAAFE
2 changed files with 56 additions and 16 deletions

View file

@ -46,7 +46,7 @@ index 092bff78ab..a987916055 100644
+ velocitySupport = getBoolean("settings.velocity-support.enabled", false);
+ velocityOnlineMode = getBoolean("settings.velocity-support.online-mode", false);
+ 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()) {
+ fatal("Velocity support is enabled, but no secret key was specified. A secret key is required!");
+ } else {

View file

@ -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>
Date: Fri, 13 May 2016 01:38:06 -0400
Subject: [PATCH] Activation Range Improvements
@ -202,18 +202,20 @@ index 5a8c60ad90..29657fed75 100644
return this.c;
}
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
+++ 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.List;
import net.minecraft.server.AxisAlignedBB;
+import net.minecraft.server.BehaviorController;
import net.minecraft.server.Chunk;
+import net.minecraft.server.ChunkProviderServer; // Paper
import net.minecraft.server.Entity;
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.EntityFireball;
import net.minecraft.server.EntityFireworks;
@ -226,7 +228,7 @@ index 92601c581c..b1cd59b047 100644
import net.minecraft.server.EntityProjectile;
import net.minecraft.server.EntityRaider;
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.EntityWither;
import net.minecraft.server.MathHelper;
@ -249,7 +251,7 @@ index 92601c581c..b1cd59b047 100644
MONSTER,
ANIMAL,
RAIDER,
@@ -58,6 +68,7 @@ public class ActivationRange
@@ -58,6 +69,7 @@ public class ActivationRange
*/
public static ActivationType initializeEntityActivationType(Entity entity)
{
@ -257,7 +259,7 @@ index 92601c581c..b1cd59b047 100644
if ( entity instanceof EntityRaider )
{
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.ANIMAL && config.animalActivationRange == 0 )
|| ( entity.activationType == ActivationType.MONSTER && config.monsterActivationRange == 0 )
@ -265,15 +267,16 @@ index 92601c581c..b1cd59b047 100644
|| entity instanceof EntityHuman
|| entity instanceof EntityProjectile
|| 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 animalActivationRange = world.spigotConfig.animalActivationRange;
final int monsterActivationRange = world.spigotConfig.monsterActivationRange;
+ final int waterActivationRange = world.spigotConfig.waterActivationRange; // Paper
+ final ChunkProviderServer chunkProvider = (ChunkProviderServer) world.getChunkProvider(); // Paper
int maxRange = Math.max( monsterActivationRange, animalActivationRange );
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.ANIMAL.boundingBox = player.getBoundingBox().grow( animalActivationRange, 256, animalActivationRange );
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 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
* @return
*/
@ -311,7 +351,7 @@ index 92601c581c..b1cd59b047 100644
}
// special cases.
if ( entity instanceof EntityLiving )
@@ -211,33 +226,49 @@ public class ActivationRange
@@ -211,33 +224,49 @@ public class ActivationRange
EntityLiving living = (EntityLiving) entity;
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
- return true;
+ return 20; // Paper
+ }
}
+ // Paper start
+ if (entity instanceof EntityInsentient && ((EntityInsentient) entity).targetSelector.hasTasks() ) {
+ return 0;
}
+ }
+ // Paper end
}
- 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;
@ -377,7 +417,7 @@ index 92601c581c..b1cd59b047 100644
// Should this entity tick?
if ( !isActive )
@@ -261,15 +293,19 @@ public class ActivationRange
@@ -261,15 +291,19 @@ public class ActivationRange
if ( ( MinecraftServer.currentTick - entity.activatedTick - 1 ) % 20 == 0 )
{
// Check immunities every 20 ticks.