forked from External/mage
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:
parent
36ccfb0a2a
commit
d57a3c100d
7 changed files with 107 additions and 61 deletions
|
|
@ -118,7 +118,7 @@ public abstract class GameImpl implements Game {
|
|||
protected Map<UUID, Counters> enterWithCounters = new HashMap<>();
|
||||
|
||||
protected GameState state;
|
||||
private transient Stack<Integer> savedStates = new Stack<>();
|
||||
private transient Stack<Integer> savedStates = new Stack<>(); // bookmarks - 0-base refs to gameStates
|
||||
protected transient GameStates gameStates = new GameStates();
|
||||
|
||||
// game states to allow player rollback
|
||||
|
|
@ -934,8 +934,7 @@ public abstract class GameImpl implements Game {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void removeBookmark(int bookmark
|
||||
) {
|
||||
public void removeBookmark(int bookmark) {
|
||||
if (!simulation) {
|
||||
if (bookmark != 0) {
|
||||
while (savedStates.size() > bookmark) {
|
||||
|
|
@ -946,6 +945,20 @@ public abstract class GameImpl implements Game {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeBookmark_v2(int bookmark) {
|
||||
if (!simulation) {
|
||||
if (bookmark != 0) {
|
||||
while (savedStates.size() >= bookmark) {
|
||||
int outdatedIndex = savedStates.pop();
|
||||
while (gameStates.getSize() - 1 >= outdatedIndex) {
|
||||
gameStates.remove(gameStates.getSize() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void clearAllBookmarks() {
|
||||
if (!simulation) {
|
||||
while (!savedStates.isEmpty()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue