From e44863f69be03c414f5f16bc7d4113618ad8a916 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 6 Mar 2021 20:42:19 +0800 Subject: [PATCH] Resize stateByID by 10% instead of a single element at a time For a complex modpack, this reduces startup time by more than 99%, because Arrays.copyOf() is invoked only dozens of times instead of hundreds of thousands of times. Fixes #3284 and #3296, and possibly others. Only patched forge 1.16.5 because that's all I'm running at the moment, but I expect the same fix can be applied elsewhere. --- .../src/main/java/org/dynmap/forge_1_16_5/DynmapPlugin.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/forge-1.16.5/src/main/java/org/dynmap/forge_1_16_5/DynmapPlugin.java b/forge-1.16.5/src/main/java/org/dynmap/forge_1_16_5/DynmapPlugin.java index 1dbbc905..b183a447 100644 --- a/forge-1.16.5/src/main/java/org/dynmap/forge_1_16_5/DynmapPlugin.java +++ b/forge-1.16.5/src/main/java/org/dynmap/forge_1_16_5/DynmapPlugin.java @@ -239,7 +239,8 @@ public class DynmapPlugin int idx = bsids.getId(bs); if (idx >= stateByID.length) { int plen = stateByID.length; - stateByID = Arrays.copyOf(stateByID, idx+1); + stateByID = Arrays.copyOf(stateByID, idx*11/10); // grow array by 10% + Log.debug("Resized stateByID from " + plen + " to " + stateByID.length); Arrays.fill(stateByID, plen, stateByID.length, DynmapBlockState.AIR); } Block b = bs.getBlock();