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:
Jesse Boyd 2016-04-02 06:03:21 +11:00
parent d7f8b3dc3b
commit 51c7b29f51
4 changed files with 24 additions and 14 deletions

View File

@ -1 +1,4 @@
#TODO README # Overview
Optimize worldedit
# Main resource page
https://www.spigotmc.org/resources/13932/

View File

@ -4,6 +4,8 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
@ -13,6 +15,7 @@ import java.util.zip.GZIPOutputStream;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.ReflectionUtils; import com.boydti.fawe.util.ReflectionUtils;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
@ -53,7 +56,7 @@ public class DiskStorageHistory implements ChangeSet, FlushableChangeSet {
* [contents]... * [contents]...
* { short rel x, short rel z, unsigned byte y, short combinedFrom, short combinedTo } * { short rel x, short rel z, unsigned byte y, short combinedFrom, short combinedTo }
*/ */
private GZIPOutputStream osBD; private OutputStream osBD;
// NBT From // NBT From
private NBTOutputStream osNBTF; private NBTOutputStream osNBTF;
@ -159,7 +162,7 @@ public class DiskStorageHistory implements ChangeSet, FlushableChangeSet {
int idTo = to.getId(); int idTo = to.getId();
int combinedTo = (FaweCache.hasData(idTo) ? ((idTo << 4) + to.getData()) : (idTo << 4)); int combinedTo = (FaweCache.hasData(idTo) ? ((idTo << 4) + to.getData()) : (idTo << 4));
CompoundTag nbtTo = FaweCache.hasNBT(idTo) ? to.getNbtData() : null; CompoundTag nbtTo = FaweCache.hasNBT(idTo) ? to.getNbtData() : null;
GZIPOutputStream stream = getBAOS(x, y, z); OutputStream stream = getBAOS(x, y, z);
//x //x
stream.write((x - ox) & 0xff); stream.write((x - ox) & 0xff);
stream.write(((x - ox) >> 8) & 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) { if (osBD != null) {
return osBD; return osBD;
} }
bdFile.getParentFile().mkdirs(); bdFile.getParentFile().mkdirs();
bdFile.createNewFile(); 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; ox = x;
oz = z; oz = z;
osBD.write((byte) (ox >> 24)); 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 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 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); gis.skip(8);
return new Iterator<Change>() { return new Iterator<Change>() {

View File

@ -3,6 +3,8 @@ package com.boydti.fawe.object.changeset;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
@ -12,6 +14,7 @@ import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.ReflectionUtils; import com.boydti.fawe.util.ReflectionUtils;
import com.google.common.collect.Iterators; import com.google.common.collect.Iterators;
@ -37,7 +40,7 @@ public class MemoryOptimizedHistory implements ChangeSet, FlushableChangeSet {
private byte[] ids; private byte[] ids;
private ByteArrayOutputStream idsStream; private ByteArrayOutputStream idsStream;
private GZIPOutputStream idsStreamZip; private OutputStream idsStreamZip;
private ArrayDeque<Change> entities; private ArrayDeque<Change> entities;
@ -71,7 +74,7 @@ public class MemoryOptimizedHistory implements ChangeSet, FlushableChangeSet {
int idTo = to.getId(); int idTo = to.getId();
int combinedTo = (FaweCache.hasData(idTo) ? ((idTo << 4) + to.getData()) : (idTo << 4)); int combinedTo = (FaweCache.hasData(idTo) ? ((idTo << 4) + to.getData()) : (idTo << 4));
CompoundTag nbtTo = FaweCache.hasNBT(idTo) ? to.getNbtData() : null; CompoundTag nbtTo = FaweCache.hasNBT(idTo) ? to.getNbtData() : null;
GZIPOutputStream stream = getBAOS(x, y, z); OutputStream stream = getBAOS(x, y, z);
//x //x
stream.write((x - ox) & 0xff); stream.write((x - ox) & 0xff);
stream.write(((x - ox) >> 8) & 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) { if (idsStreamZip != null) {
return idsStreamZip; return idsStreamZip;
} }
idsStream = new ByteArrayOutputStream(9216); idsStream = new ByteArrayOutputStream(9216);
idsStreamZip = new GZIPOutputStream(idsStream, true); idsStreamZip = Settings.COMPRESS_HISTORY ? new GZIPOutputStream(idsStream, true) : idsStream;
ox = x; ox = x;
oz = z; oz = z;
return idsStreamZip; return idsStreamZip;
@ -139,7 +142,8 @@ public class MemoryOptimizedHistory implements ChangeSet, FlushableChangeSet {
if (ids == null) { if (ids == null) {
idsIterator = new ArrayList().iterator(); idsIterator = new ArrayList().iterator();
} else { } 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>() { idsIterator = new Iterator<Change>() {
private final Iterator<CompoundTag> lastFromIter = fromTags != null ? fromTags.iterator() : null; private final Iterator<CompoundTag> lastFromIter = fromTags != null ? fromTags.iterator() : null;

View File

@ -46,7 +46,6 @@ import com.boydti.fawe.object.EditSessionWrapper;
import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.NullChangeSet; import com.boydti.fawe.object.NullChangeSet;
import com.boydti.fawe.object.RegionWrapper; 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.DiskStorageHistory;
import com.boydti.fawe.object.changeset.MemoryOptimizedHistory; import com.boydti.fawe.object.changeset.MemoryOptimizedHistory;
import com.boydti.fawe.object.extent.FastWorldEditExtent; import com.boydti.fawe.object.extent.FastWorldEditExtent;
@ -244,8 +243,7 @@ public class EditSession implements Extent {
this.changeSet = new NullChangeSet(); this.changeSet = new NullChangeSet();
return; return;
} }
this.changeSet = Settings.STORE_HISTORY_ON_DISK ? new DiskStorageHistory(actor.getUniqueId().toString()) : new MemoryOptimizedHistory();
this.changeSet = Settings.STORE_HISTORY_ON_DISK ? new DiskStorageHistory(actor.getUniqueId().toString()) : Settings.COMPRESS_HISTORY ? new MemoryOptimizedHistory() : new CPUOptimizedHistory();
Extent extent; Extent extent;
final String name = actor.getName(); final String name = actor.getName();
final FawePlayer<Object> fp = FawePlayer.wrap(name); final FawePlayer<Object> fp = FawePlayer.wrap(name);