9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-30 20:39:21 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0135-Slight-optimizations-to-VarInt.patch
Taiyou cd7689b16f Chunk improvements (#231)
* perf: SpatialPlayerIndex for isChunkNearPlayer

* perf: ensureCapacity with collectTickingChunks

* perf: optimize getSlopeDistance

* perf: optimize AABB Intersections

* perf: implement custom arrays for regions and caches

* perf: Improve SortedArraySet sorting (needs testing)

* rebase 1.21.4

* perf: optimize ClientBoundLightUpdatePacketData

* perf: O(1) Array Writes during Chunk Loading

* perf: Optimize LinearPalette (no not the linear format)

* perf: Rewrite ConcurrentLongHashSet

* rebase 1.21.4

* Fix Multithreaded Tracker (#236)

* duke gonna arrest me

* i hate git v2

* rebase

* dont worry ill change the name of this patch

* perf: Rewrite ConcurrentLongHashSet again

* perf: Optimize sendChunk

* [ci skip]

* cleanup

* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

* cleanup

* remove streams on LinearPalette and SerializableChunkData

* actually commit them lmao

* actually commit them lmao 2

* fix

* rebase

* perf: clone less (could help with skyblocks)

* perf: more unload stuff

* perf: manual loop unrolling and bulk copy

* initial size for SerializeableChunkData

* perf: async chunkSend

* cleanup asyncChunkSend

* remove experimental tag

* rebase

---------

Co-authored-by: Creeam <102713261+HaHaWTH@users.noreply.github.com>
Co-authored-by: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
2025-03-05 22:45:26 +03:00

82 lines
3.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Mon, 24 Feb 2025 21:11:09 +0100
Subject: [PATCH] Slight optimizations to VarInt
diff --git a/net/minecraft/network/VarInt.java b/net/minecraft/network/VarInt.java
index 6f8dd31582f0e1d3a71acc7a142c1f4ec0539d9e..043db53ee627ac13e3a952c8d5beba5065ecbb48 100644
--- a/net/minecraft/network/VarInt.java
+++ b/net/minecraft/network/VarInt.java
@@ -51,35 +51,41 @@ public class VarInt {
}
public static ByteBuf write(ByteBuf buffer, int value) {
- // Gale start - Velocity - optimized VarInt#write
- if ((value & 0xFFFFFF80) == 0) {
- buffer.writeByte(value);
- } else if ((value & 0xFFFFC000) == 0) {
- int w = (value & 0x7F) << 8
- | (value >>> 7)
- | 0x00008000;
- buffer.writeShort(w);
- } else if ((value & 0xFFE00000) == 0) {
- int w = (value & 0x7F) << 16
- | (value & 0x3F80) << 1
- | (value >>> 14)
- | 0x00808000;
- buffer.writeMedium(w);
- } else if ((value & 0xF0000000) == 0) {
- int w = (value & 0x7F) << 24
- | ((value & 0x3F80) << 9)
- | (value & 0x1FC000) >> 6
- | (value >>> 21)
- | 0x80808000;
- buffer.writeInt(w);
- } else {
- int w = (value & 0x7F) << 24
- | (value & 0x3F80) << 9
- | (value & 0x1FC000) >> 6
- | ((value >>> 21) & 0x7F)
- | 0x80808080;
- buffer.writeInt(w);
- buffer.writeByte(value >>> 28);
+ // Gale start - Velocity - optimized VarInt#write // Leaf - help JIT by using switch case
+ int bytesNeeded = getByteSize(value);
+
+ switch (bytesNeeded) {
+ case 1:
+ buffer.writeByte(value);
+ break;
+ case 2:
+ int w2 = ((value & 0x7F) << 8) | (value >>> 7) | 0x00008000;
+ buffer.writeShort(w2);
+ break;
+ case 3:
+ int w3 = (value & 0x7F) << 16
+ | (value & 0x3F80) << 1
+ | (value >>> 14)
+ | 0x00808000;
+ buffer.writeMedium(w3);
+ break;
+ case 4:
+ int w4 = (value & 0x7F) << 24
+ | ((value & 0x3F80) << 9)
+ | (value & 0x1FC000) >> 6
+ | (value >>> 21)
+ | 0x80808000;
+ buffer.writeInt(w4);
+ break;
+ case 5:
+ int w5 = (value & 0x7F) << 24
+ | (value & 0x3F80) << 9
+ | (value & 0x1FC000) >> 6
+ | ((value >>> 21) & 0x7F)
+ | 0x80808080;
+ buffer.writeInt(w5);
+ buffer.writeByte(value >>> 28);
+ break;
}
return buffer;
}