mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2024-11-24 19:46:34 +01:00
Readme + history tweak
Switched to MemoryOptimizedHistory without compression by default. The increase in cpu is negligable but the reduction in memory is substantial. Further compression can still be enabled.
This commit is contained in:
parent
d7f8b3dc3b
commit
51c7b29f51
@ -1 +1,4 @@
|
||||
#TODO README
|
||||
# Overview
|
||||
Optimize worldedit
|
||||
# Main resource page
|
||||
https://www.spigotmc.org/resources/13932/
|
@ -4,6 +4,8 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
@ -13,6 +15,7 @@ import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.ReflectionUtils;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
@ -53,7 +56,7 @@ public class DiskStorageHistory implements ChangeSet, FlushableChangeSet {
|
||||
* [contents]...
|
||||
* { short rel x, short rel z, unsigned byte y, short combinedFrom, short combinedTo }
|
||||
*/
|
||||
private GZIPOutputStream osBD;
|
||||
private OutputStream osBD;
|
||||
|
||||
// NBT From
|
||||
private NBTOutputStream osNBTF;
|
||||
@ -159,7 +162,7 @@ public class DiskStorageHistory implements ChangeSet, FlushableChangeSet {
|
||||
int idTo = to.getId();
|
||||
int combinedTo = (FaweCache.hasData(idTo) ? ((idTo << 4) + to.getData()) : (idTo << 4));
|
||||
CompoundTag nbtTo = FaweCache.hasNBT(idTo) ? to.getNbtData() : null;
|
||||
GZIPOutputStream stream = getBAOS(x, y, z);
|
||||
OutputStream stream = getBAOS(x, y, z);
|
||||
//x
|
||||
stream.write((x - ox) & 0xff);
|
||||
stream.write(((x - ox) >> 8) & 0xff);
|
||||
@ -197,13 +200,14 @@ public class DiskStorageHistory implements ChangeSet, FlushableChangeSet {
|
||||
}
|
||||
}
|
||||
|
||||
private GZIPOutputStream getBAOS(int x, int y, int z) throws IOException {
|
||||
private OutputStream getBAOS(int x, int y, int z) throws IOException {
|
||||
if (osBD != null) {
|
||||
return osBD;
|
||||
}
|
||||
bdFile.getParentFile().mkdirs();
|
||||
bdFile.createNewFile();
|
||||
osBD = new GZIPOutputStream(new FileOutputStream(bdFile), true);
|
||||
FileOutputStream stream = new FileOutputStream(bdFile);
|
||||
osBD = Settings.COMPRESS_HISTORY ? new GZIPOutputStream(stream, true) : stream;
|
||||
ox = x;
|
||||
oz = z;
|
||||
osBD.write((byte) (ox >> 24));
|
||||
@ -277,7 +281,8 @@ public class DiskStorageHistory implements ChangeSet, FlushableChangeSet {
|
||||
final NBTInputStream nbtf = osNBTF != null ? new NBTInputStream(new GZIPInputStream(new FileInputStream(nbtfFile))) : null;
|
||||
final NBTInputStream nbtt = osNBTT != null ? new NBTInputStream(new GZIPInputStream(new FileInputStream(nbttFile))) : null;
|
||||
|
||||
final GZIPInputStream gis = new GZIPInputStream(new FileInputStream(bdFile));
|
||||
FileInputStream fis = new FileInputStream(bdFile);
|
||||
final InputStream gis = Settings.COMPRESS_HISTORY ? new GZIPInputStream(fis) : fis;
|
||||
gis.skip(8);
|
||||
return new Iterator<Change>() {
|
||||
|
||||
|
@ -3,6 +3,8 @@ package com.boydti.fawe.object.changeset;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@ -12,6 +14,7 @@ import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.ReflectionUtils;
|
||||
import com.google.common.collect.Iterators;
|
||||
@ -37,7 +40,7 @@ public class MemoryOptimizedHistory implements ChangeSet, FlushableChangeSet {
|
||||
|
||||
private byte[] ids;
|
||||
private ByteArrayOutputStream idsStream;
|
||||
private GZIPOutputStream idsStreamZip;
|
||||
private OutputStream idsStreamZip;
|
||||
|
||||
private ArrayDeque<Change> entities;
|
||||
|
||||
@ -71,7 +74,7 @@ public class MemoryOptimizedHistory implements ChangeSet, FlushableChangeSet {
|
||||
int idTo = to.getId();
|
||||
int combinedTo = (FaweCache.hasData(idTo) ? ((idTo << 4) + to.getData()) : (idTo << 4));
|
||||
CompoundTag nbtTo = FaweCache.hasNBT(idTo) ? to.getNbtData() : null;
|
||||
GZIPOutputStream stream = getBAOS(x, y, z);
|
||||
OutputStream stream = getBAOS(x, y, z);
|
||||
//x
|
||||
stream.write((x - ox) & 0xff);
|
||||
stream.write(((x - ox) >> 8) & 0xff);
|
||||
@ -119,12 +122,12 @@ public class MemoryOptimizedHistory implements ChangeSet, FlushableChangeSet {
|
||||
}
|
||||
}
|
||||
|
||||
private GZIPOutputStream getBAOS(int x, int y, int z) throws IOException {
|
||||
private OutputStream getBAOS(int x, int y, int z) throws IOException {
|
||||
if (idsStreamZip != null) {
|
||||
return idsStreamZip;
|
||||
}
|
||||
idsStream = new ByteArrayOutputStream(9216);
|
||||
idsStreamZip = new GZIPOutputStream(idsStream, true);
|
||||
idsStreamZip = Settings.COMPRESS_HISTORY ? new GZIPOutputStream(idsStream, true) : idsStream;
|
||||
ox = x;
|
||||
oz = z;
|
||||
return idsStreamZip;
|
||||
@ -139,7 +142,8 @@ public class MemoryOptimizedHistory implements ChangeSet, FlushableChangeSet {
|
||||
if (ids == null) {
|
||||
idsIterator = new ArrayList().iterator();
|
||||
} else {
|
||||
final GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(ids));
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(ids);
|
||||
final InputStream gis = Settings.COMPRESS_HISTORY ? new GZIPInputStream(bais) : bais;
|
||||
idsIterator = new Iterator<Change>() {
|
||||
|
||||
private final Iterator<CompoundTag> lastFromIter = fromTags != null ? fromTags.iterator() : null;
|
||||
|
@ -46,7 +46,6 @@ import com.boydti.fawe.object.EditSessionWrapper;
|
||||
import com.boydti.fawe.object.FawePlayer;
|
||||
import com.boydti.fawe.object.NullChangeSet;
|
||||
import com.boydti.fawe.object.RegionWrapper;
|
||||
import com.boydti.fawe.object.changeset.CPUOptimizedHistory;
|
||||
import com.boydti.fawe.object.changeset.DiskStorageHistory;
|
||||
import com.boydti.fawe.object.changeset.MemoryOptimizedHistory;
|
||||
import com.boydti.fawe.object.extent.FastWorldEditExtent;
|
||||
@ -244,8 +243,7 @@ public class EditSession implements Extent {
|
||||
this.changeSet = new NullChangeSet();
|
||||
return;
|
||||
}
|
||||
|
||||
this.changeSet = Settings.STORE_HISTORY_ON_DISK ? new DiskStorageHistory(actor.getUniqueId().toString()) : Settings.COMPRESS_HISTORY ? new MemoryOptimizedHistory() : new CPUOptimizedHistory();
|
||||
this.changeSet = Settings.STORE_HISTORY_ON_DISK ? new DiskStorageHistory(actor.getUniqueId().toString()) : new MemoryOptimizedHistory();
|
||||
Extent extent;
|
||||
final String name = actor.getName();
|
||||
final FawePlayer<Object> fp = FawePlayer.wrap(name);
|
||||
|
Loading…
Reference in New Issue
Block a user