9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0277-optimize-SimpleBitStorage-object-layout.patch

42 lines
3.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: hayanesuru <hayanesuru@outlook.jp>
Date: Sat, 9 Aug 2025 14:55:00 +0900
Subject: [PATCH] optimize SimpleBitStorage object layout
diff --git a/net/minecraft/util/SimpleBitStorage.java b/net/minecraft/util/SimpleBitStorage.java
index 8091f0c0a536047ead4966e70785962e87faad9a..8aec073db74a4d0a21c8a423586d108c6add9ad5 100644
--- a/net/minecraft/util/SimpleBitStorage.java
+++ b/net/minecraft/util/SimpleBitStorage.java
@@ -204,8 +204,8 @@ public class SimpleBitStorage implements BitStorage {
private final long mask;
private final int size;
private final int valuesPerLong;
- private final int divideMul; private final long divideMulUnsigned; // Paper - Perf: Optimize SimpleBitStorage; referenced in b(int) with 2 Integer.toUnsignedLong calls
- private final int divideAdd; private final long divideAddUnsigned; // Paper - Perf: Optimize SimpleBitStorage
+ private final int divideMul; /*private final long divideMulUnsigned;*/ // Paper - Perf: Optimize SimpleBitStorage; referenced in b(int) with 2 Integer.toUnsignedLong calls // Leaf - optimize SimpleBitStorage object layout
+ private final int divideAdd; /*private final long divideAddUnsigned;*/ // Paper - Perf: Optimize SimpleBitStorage // Leaf - optimize SimpleBitStorage object layout
private final int divideShift;
// Paper start - optimise bitstorage read/write operations
@@ -262,8 +262,8 @@ public class SimpleBitStorage implements BitStorage {
this.mask = (1L << bits) - 1L;
this.valuesPerLong = (char)(64 / bits);
int i = 3 * (this.valuesPerLong - 1);
- this.divideMul = MAGIC[i + 0]; this.divideMulUnsigned = Integer.toUnsignedLong(this.divideMul); // Paper - Perf: Optimize SimpleBitStorage
- this.divideAdd = MAGIC[i + 1]; this.divideAddUnsigned = Integer.toUnsignedLong(this.divideAdd); // Paper - Perf: Optimize SimpleBitStorage
+ this.divideMul = MAGIC[i + 0]; /*this.divideMulUnsigned = Integer.toUnsignedLong(this.divideMul);*/ // Paper - Perf: Optimize SimpleBitStorage // Leaf - optimize SimpleBitStorage object layout
+ this.divideAdd = MAGIC[i + 1]; /*this.divideAddUnsigned = Integer.toUnsignedLong(this.divideAdd);*/ // Paper - Perf: Optimize SimpleBitStorage // Leaf - optimize SimpleBitStorage object layout
this.divideShift = MAGIC[i + 2];
int i1 = (size + this.valuesPerLong - 1) / this.valuesPerLong;
if (data != null) {
@@ -285,7 +285,7 @@ public class SimpleBitStorage implements BitStorage {
}
private int cellIndex(int index) {
- return (int)(index * this.divideMulUnsigned + this.divideAddUnsigned >> 32 >> this.divideShift); // Paper - Perf: Optimize SimpleBitStorage
+ return (int)(index * Integer.toUnsignedLong(this.divideMul) + Integer.toUnsignedLong(this.divideAdd) >> 32 >> this.divideShift); // Paper - Perf: Optimize SimpleBitStorage // Leaf - optimize SimpleBitStorage object layout
}
@Override