PaperMC/patches/server/0086-Optimize-DataBits.patch

119 lines
5.8 KiB
Diff
Raw Normal View History

2021-06-12 05:07:57 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 5 Apr 2016 21:38:58 -0400
Subject: [PATCH] Optimize DataBits
Remove Debug checks as these are super hot and causing noticeable hits
Before: http://i.imgur.com/nQsMzAE.png
After: http://i.imgur.com/nJ46crB.png
Optimize redundant converting of static fields into an unsigned long each call by precomputing it in ctor
2021-11-23 14:22:49 +01:00
diff --git a/src/main/java/net/minecraft/util/SimpleBitStorage.java b/src/main/java/net/minecraft/util/SimpleBitStorage.java
2023-09-22 19:59:56 +02:00
index f677cc252d5510a2365e73dc42bd266e56115e83..2b3fd62dca2d1475075b5dcde56cea85b749cb44 100644
2021-11-23 14:22:49 +01:00
--- a/src/main/java/net/minecraft/util/SimpleBitStorage.java
+++ b/src/main/java/net/minecraft/util/SimpleBitStorage.java
@@ -11,8 +11,8 @@ public class SimpleBitStorage implements BitStorage {
2021-06-12 05:07:57 +02:00
private final long mask;
private final int size;
private final int valuesPerLong;
- private final int divideMul;
- private final int divideAdd;
+ private final int divideMul; private final long divideMulUnsigned; // Paper - referenced in b(int) with 2 Integer.toUnsignedLong calls
+ private final int divideAdd; private final long divideAddUnsigned; // Paper
private final int divideShift;
2022-06-07 21:55:39 +02:00
public SimpleBitStorage(int elementBits, int size, int[] data) {
2021-11-23 14:22:49 +01:00
@@ -56,8 +56,8 @@ public class SimpleBitStorage implements BitStorage {
2021-06-12 05:07:57 +02:00
this.mask = (1L << elementBits) - 1L;
this.valuesPerLong = (char)(64 / elementBits);
int i = 3 * (this.valuesPerLong - 1);
- this.divideMul = MAGIC[i + 0];
- this.divideAdd = MAGIC[i + 1];
2021-11-23 14:22:49 +01:00
+ this.divideMul = MAGIC[i + 0]; this.divideMulUnsigned = Integer.toUnsignedLong(this.divideMul); // Paper
+ this.divideAdd = MAGIC[i + 1]; this.divideAddUnsigned = Integer.toUnsignedLong(this.divideAdd); // Paper
2021-06-12 05:07:57 +02:00
this.divideShift = MAGIC[i + 2];
int j = (size + this.valuesPerLong - 1) / this.valuesPerLong;
2021-11-23 14:22:49 +01:00
if (data != null) {
@@ -73,15 +73,15 @@ public class SimpleBitStorage implements BitStorage {
2021-06-12 05:07:57 +02:00
}
private int cellIndex(int index) {
- long l = Integer.toUnsignedLong(this.divideMul);
- long m = Integer.toUnsignedLong(this.divideAdd);
- return (int)((long)index * l + m >> 32 >> this.divideShift);
+ //long l = Integer.toUnsignedLong(this.divideMul); // Paper
+ //long m = Integer.toUnsignedLong(this.divideAdd); // Paper
+ return (int) ((long) index * this.divideMulUnsigned + this.divideAddUnsigned >> 32 >> this.divideShift); // Paper
}
2021-11-23 14:22:49 +01:00
@Override
2021-06-12 05:07:57 +02:00
- public int getAndSet(int index, int value) {
- Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index);
- Validate.inclusiveBetween(0L, this.mask, (long)value);
+ public final int getAndSet(int index, int value) { // Paper - make final for inline
+ //Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index); // Paper
+ //Validate.inclusiveBetween(0L, this.mask, (long)value); // Paper
int i = this.cellIndex(index);
long l = this.data[i];
int j = (index - i * this.valuesPerLong) * this.bits;
2021-11-23 14:22:49 +01:00
@@ -91,9 +91,9 @@ public class SimpleBitStorage implements BitStorage {
2021-06-12 05:07:57 +02:00
}
2021-11-23 14:22:49 +01:00
@Override
2021-06-12 05:07:57 +02:00
- public void set(int index, int value) {
- Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index);
- Validate.inclusiveBetween(0L, this.mask, (long)value);
+ public final void set(int index, int value) { // Paper - make final for inline
+ //Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index); // Paper
+ //Validate.inclusiveBetween(0L, this.mask, (long)value); // Paper
int i = this.cellIndex(index);
long l = this.data[i];
int j = (index - i * this.valuesPerLong) * this.bits;
2021-11-23 14:22:49 +01:00
@@ -101,8 +101,8 @@ public class SimpleBitStorage implements BitStorage {
2021-06-12 05:07:57 +02:00
}
2021-11-23 14:22:49 +01:00
@Override
2021-06-12 05:07:57 +02:00
- public int get(int index) {
- Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index);
+ public final int get(int index) { // Paper - make final for inline
+ //Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index);
int i = this.cellIndex(index);
long l = this.data[i];
int j = (index - i * this.valuesPerLong) * this.bits;
diff --git a/src/main/java/net/minecraft/util/ZeroBitStorage.java b/src/main/java/net/minecraft/util/ZeroBitStorage.java
2023-09-22 19:59:56 +02:00
index 0710c72441c832a93275f3f9bd9dd7643dc0f229..f0f764f36fb92c64ab2dc8a0a50c3f48321c3c9a 100644
--- a/src/main/java/net/minecraft/util/ZeroBitStorage.java
+++ b/src/main/java/net/minecraft/util/ZeroBitStorage.java
@@ -13,21 +13,21 @@ public class ZeroBitStorage implements BitStorage {
}
@Override
- public int getAndSet(int index, int value) {
- Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index);
- Validate.inclusiveBetween(0L, 0L, (long)value);
+ public final int getAndSet(int index, int value) { // Paper - make final for inline
+ //Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index); // Paper
+ //Validate.inclusiveBetween(0L, 0L, (long)value); // Paper
return 0;
}
@Override
- public void set(int index, int value) {
- Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index);
- Validate.inclusiveBetween(0L, 0L, (long)value);
+ public final void set(int index, int value) { // Paper - make final for inline
+ //Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index); // Paper
+ //Validate.inclusiveBetween(0L, 0L, (long)value); // Paper
}
@Override
- public int get(int index) {
- Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index);
+ public final int get(int index) { // Paper - make final for inline
+ //Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index); // Paper
return 0;
}