From: Tuukka Lehtonen Date: Thu, 4 Jun 2020 22:33:16 +0000 (+0300) Subject: Avoid useless reallocation of empty TreeMaps and map iterators X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F94%2F4294%2F1;p=simantics%2Fplatform.git Avoid useless reallocation of empty TreeMaps and map iterators The problem was that when the database is doing work, MainProgram.run runs in pretty much busy loop mode and previously it was always allocating a new TreeMap on each round and also calling Map.entrySet() to get construct iterators for empty TreeMaps which eventually accumulates up to somewhat signinificant amount of memory allocated. Possibly an even more efficient way would be to have the Map be a closed hashing hashmap instead and then sorting the data for iteration separately. gitlab #548 Change-Id: Ib2208dc35b270c9d682362d45f24f1fe01bb8969 --- diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/MainProgram.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/MainProgram.java index 1e4b5cbac..52be328eb 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/MainProgram.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/MainProgram.java @@ -70,7 +70,7 @@ public class MainProgram implements Runnable, Closeable { this.updateSchedules = new ArrayList[CLUSTER_THREADS]; for(int i=0;i(); + updateSchedules[i] = new ArrayList<>(); } } @@ -93,11 +93,13 @@ public class MainProgram implements Runnable, Closeable { try { + TreeMap> updates = new TreeMap<>(clusterComparator); + main: while(alive) { - TreeMap> updates = new TreeMap>(clusterComparator); - + if (!updates.isEmpty()) + updates.clear(); operationQueue.pumpUpdates(updates); if(updates.isEmpty()) { @@ -165,6 +167,9 @@ public class MainProgram implements Runnable, Closeable { for(int i=0;i> entry : updates.entrySet()) {