aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0296-Optimize-RegistryID.c.patch
blob: f61f8d6d682cc74015972bf726752534afd8821f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
From 82c0f3c7cdd722722ee6bfd3047ecc52fab78026 Mon Sep 17 00:00:00 2001
From: Andrew Steinborn <git@steinborn.me>
Date: Mon, 23 Jul 2018 13:08:19 -0400
Subject: [PATCH] Optimize RegistryID.c()

This is a frequent hotspot for world loading/saving.

diff --git a/src/main/java/net/minecraft/server/RegistryID.java b/src/main/java/net/minecraft/server/RegistryID.java
index 5a5c464ea1..37641fa865 100644
--- a/src/main/java/net/minecraft/server/RegistryID.java
+++ b/src/main/java/net/minecraft/server/RegistryID.java
@@ -14,12 +14,14 @@ public class RegistryID<K> implements Registry<K> {
     private K[] d;
     private int e;
     private int f;
+    private java.util.BitSet usedIds; // Paper
 
     public RegistryID(int i) {
         i = (int) ((float) i / 0.8F);
         this.b = (K[]) (new Object[i]); // Paper - decompile fix
         this.c = new int[i];
         this.d = (K[]) (new Object[i]); // Paper - decompile fix
+        this.usedIds = new java.util.BitSet(); // Paper
     }
 
     public int getId(@Nullable K k0) {
@@ -43,9 +45,14 @@ public class RegistryID<K> implements Registry<K> {
     }
 
     private int c() {
+        // Paper start
+        /*
         while (this.e < this.d.length && this.d[this.e] != null) {
             ++this.e;
         }
+        */
+        this.e = this.usedIds.nextClearBit(0);
+        // Paper end
 
         return this.e;
     }
@@ -59,6 +66,7 @@ public class RegistryID<K> implements Registry<K> {
         this.d = (K[]) (new Object[i]); // Paper - decompile fix
         this.e = 0;
         this.f = 0;
+        this.usedIds.clear(); // Paper
 
         for (int j = 0; j < ak.length; ++j) {
             if (ak[j] != null) {
@@ -84,6 +92,7 @@ public class RegistryID<K> implements Registry<K> {
         this.b[k] = k0;
         this.c[k] = i;
         this.d[i] = k0;
+        this.usedIds.set(i); // Paper
         ++this.f;
         if (i == this.e) {
             ++this.e;
@@ -148,6 +157,7 @@ public class RegistryID<K> implements Registry<K> {
         Arrays.fill(this.d, (Object) null);
         this.e = 0;
         this.f = 0;
+        this.usedIds.clear(); // Paper
     }
 
     public int b() {
-- 
2.21.0