9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-28 03:19:21 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0128-Bulk-writes-to-writeLongArray-during-chunk-loading.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

44 lines
1.8 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Fri, 21 Feb 2025 15:06:55 +0100
Subject: [PATCH] Bulk writes to writeLongArray during chunk loading
diff --git a/net/minecraft/network/FriendlyByteBuf.java b/net/minecraft/network/FriendlyByteBuf.java
index abb0141426fd716e79a947b9498a8351daa342fc..838a7d64e717759f506e64c74eb76eea05f72811 100644
--- a/net/minecraft/network/FriendlyByteBuf.java
+++ b/net/minecraft/network/FriendlyByteBuf.java
@@ -341,9 +341,30 @@ public class FriendlyByteBuf extends ByteBuf {
public FriendlyByteBuf writeLongArray(long[] array) {
this.writeVarInt(array.length);
+ if (array.length == 0) {
+ return this;
+ }
+
+ this.source.ensureWritable(array.length * Long.BYTES);
+ int writerIndex = this.source.writerIndex();
+
+ if (this.source.hasArray()) {
+ byte[] dest = this.source.array();
+ int offset = this.source.arrayOffset() + writerIndex;
- for (long l : array) {
- this.writeLong(l);
+ ByteBuffer buf = ByteBuffer.wrap(dest, offset, array.length * Long.BYTES).order(this.source.order());
+ buf.asLongBuffer().put(array);
+
+ this.source.writerIndex(writerIndex + array.length * Long.BYTES);
+ } else if (this.source.nioBufferCount() > 0) {
+ ByteBuffer nioBuf = this.source.nioBuffer(writerIndex, array.length * Long.BYTES);
+ nioBuf.asLongBuffer().put(array);
+ this.source.writerIndex(writerIndex + array.length * Long.BYTES);
+ } else {
+ ByteBuffer temp = ByteBuffer.allocate(array.length * Long.BYTES).order(this.source.order());
+ temp.asLongBuffer().put(array);
+ temp.rewind();
+ this.source.writeBytes(temp);
}
return this;