Paper 1.13 Backport: Optimize RegistryID.c() w/ Add changes note

This commit is contained in:
Sotr
2018-07-25 01:28:58 +08:00
parent 144c9e08f5
commit bca8f20393
2 changed files with 20 additions and 3 deletions

View File

@@ -10,6 +10,10 @@ import java.util.Map;
import com.destroystokyo.paper.PaperConfig; // Paper
import java.util.LinkedHashMap; // Paper
/**
* Akarin Changes Note
* 1) Removes unneed synchronization (performance)
*/
public class RegionFileCache {
public static final Map<File, RegionFile> a = new LinkedHashMap(PaperConfig.regionFileCacheSize, 0.75f, true); // Spigot - private -> public, Paper - HashMap -> LinkedHashMap
@@ -94,7 +98,7 @@ public class RegionFileCache {
}
// CraftBukkit start - call sites hoisted for synchronization
public static /*synchronized*/ NBTTagCompound d(File file, int i, int j) throws IOException { // Akarin - remove synchronization // OBFHELPER: read
public static /*synchronized*/ NBTTagCompound d(File file, int i, int j) throws IOException { // Akarin - 1.13 backport - remove synchronization // OBFHELPER: read
RegionFile regionfile = a(file, i, j);
DataInputStream datainputstream = regionfile.a(i & 31, j & 31);
@@ -106,7 +110,7 @@ public class RegionFileCache {
return NBTCompressedStreamTools.a(datainputstream);
}
public static /*synchronized*/ void e(File file, int i, int j, NBTTagCompound nbttagcompound) throws IOException { // Akarin - remove synchronization // OBFHELPER: write
public static /*synchronized*/ void e(File file, int i, int j, NBTTagCompound nbttagcompound) throws IOException { // Akarin - 1.13 backport - remove synchronization // OBFHELPER: write
RegionFile regionfile = a(file, i, j);
DataOutputStream dataoutputstream = regionfile.b(i & 31, j & 31);
@@ -115,7 +119,7 @@ public class RegionFileCache {
}
// CraftBukkit end
public static /*synchronized*/ boolean chunkExists(File file, int i, int j) { // Akarin - remove synchronization
public static /*synchronized*/ boolean chunkExists(File file, int i, int j) { // Akarin - 1.13 backport - remove synchronization
RegionFile regionfile = b(file, i, j);
return regionfile != null ? regionfile.c(i & 31, j & 31) : false;

View File

@@ -5,6 +5,10 @@ import com.google.common.collect.Iterators;
import java.util.Iterator;
import javax.annotation.Nullable;
/**
* Akarin Changes Note
* 1) BitSet for faster access (performance)
*/
public class RegistryID<K> implements Registry {
private static final Object a = null;
@@ -13,12 +17,14 @@ public class RegistryID<K> implements Registry {
private K[] d;
private int e;
private int f;
private java.util.BitSet usedIds; // Akarin - 1.13 backport
public RegistryID(int i) {
i = (int) ((float) i / 0.8F);
this.b = (K[]) (new Object[i]);
this.c = new int[i];
this.d = (K[]) (new Object[i]);
this.usedIds = new java.util.BitSet(); // Akarin - 1.13 backport
}
public int getId(@Nullable K k0) {
@@ -42,9 +48,14 @@ public class RegistryID<K> implements Registry {
}
private int c() {
// Akarin start - 1.13 backport
/*
while (this.e < this.d.length && this.d[this.e] != null) {
++this.e;
}
*/
this.e = this.usedIds.nextClearBit(0);
// Akarin end - 1.13 backport
return this.e;
}
@@ -58,6 +69,7 @@ public class RegistryID<K> implements Registry {
this.d = (K[]) (new Object[i]);
this.e = 0;
this.f = 0;
this.usedIds.clear(); // Akarin - 1.13 backport
for (int j = 0; j < aobject.length; ++j) {
if (aobject[j] != null) {
@@ -83,6 +95,7 @@ public class RegistryID<K> implements Registry {
this.b[k] = k0;
this.c[k] = i;
this.d[i] = k0;
this.usedIds.set(i); // Akarin - 1.13 backport
++this.f;
if (i == this.e) {
++this.e;