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.
This commit is contained in:
Michael 2021-03-06 20:42:19 +08:00 committed by GitHub
parent b1f6b52d6d
commit e44863f69b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();