Performance: fixed server's big memory usage in long games and in big stack sizes (related to #11285, fixes #9302)

This commit is contained in:
Oleg Agafonov 2023-10-14 15:54:10 +04:00
parent 36ccfb0a2a
commit d57a3c100d
7 changed files with 107 additions and 61 deletions

View file

@ -51,39 +51,4 @@ public class Copier<T> {
return copy;
}
public byte[] copyCompressed(T obj) {
FastByteArrayOutputStream fbos = null;
ObjectOutputStream out = null;
try {
fbos = new FastByteArrayOutputStream();
out = new ObjectOutputStream(new GZIPOutputStream(fbos));
// Write the object out to a byte array
out.writeObject(obj);
out.flush();
byte[] copy = new byte[fbos.getSize()];
System.arraycopy(fbos.getByteArray(), 0, copy, 0, fbos.getSize());
return copy;
}
catch(IOException e) {
e.printStackTrace();
} finally {
StreamUtils.closeQuietly(fbos);
StreamUtils.closeQuietly(out);
}
return null;
}
public T uncompressCopy(byte[] buffer) {
T copy = null;
try (ObjectInputStream in = new CopierObjectInputStream(loader, new GZIPInputStream(new ByteArrayInputStream(buffer)))) {
copy = (T) in.readObject();
}
catch(IOException | ClassNotFoundException e) {
e.printStackTrace();
}
return copy;
}
}