Skip to content

Commit e6822b8

Browse files
author
Michael Schroeder
committed
Improve heatmap switch performance:
- Force System.gc() only once per switch - Do not detach topLayer()
1 parent 5962e37 commit e6822b8

File tree

9 files changed

+39
-24
lines changed

9 files changed

+39
-24
lines changed

org.gitools.api/src/main/java/org/gitools/api/matrix/IMatrix.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ public interface IMatrix extends IResource {
4747
* This method is called when the matrix is not in use.
4848
* <p/>
4949
* It's a good practice to free all the caching memory usage.
50+
* @param topLayer
5051
*/
51-
void detach();
52+
void detach(IMatrixLayer topLayer);
5253

5354
<T> void setMetadata(IKey<T> key, T value);
5455

org.gitools.heatmap/src/main/java/org/gitools/heatmap/Heatmap.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,17 @@ public void setColumns(HeatmapDimension columns) {
133133
firePropertyChange(PROPERTY_COLUMNS, old, columns);
134134
}
135135

136-
public void detach() {
136+
public void detach(IMatrixLayer topLayer) {
137137
if (data != null && data.isLoaded()) {
138-
data.get().detach();
138+
data.get().detach(topLayer);
139139
}
140140

141-
// Detach heatmap cache
142-
//this.cache = null;
143-
144141
// Detach layers cache
145142
for (HeatmapLayer layer : layers) {
146-
layer.detach();
143+
if (layer != topLayer) {
144+
layer.detach();
145+
}
147146
}
148-
149-
// Force garbage collection
150-
System.gc();
151147
}
152148

153149
public void init() {

org.gitools.matrix/src/main/java/org/gitools/matrix/model/AbstractMatrix.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,13 @@ public MD getColumns() {
9898
}
9999

100100
@Override
101-
public void detach() {
101+
public void detach(IMatrixLayer topLayer) {
102102
this.cache = null;
103103

104104
for (IMatrixLayer layer : layers) {
105+
if (topLayer == layer) {
106+
continue;
107+
}
105108
layer.detach();
106109
}
107110
}

org.gitools.matrix/src/main/java/org/gitools/matrix/model/MatrixWrapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public IMatrix subset(IMatrixDimension... dimensionSubsets) {
7979
}
8080

8181
@Override
82-
public void detach() {
83-
wrapMatrix.detach();
82+
public void detach(IMatrixLayer topLayer) {
83+
wrapMatrix.detach(topLayer);
8484
}
8585

8686
@Override

org.gitools.matrix/src/main/java/org/gitools/matrix/model/compressmatrix/CompressMatrix.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private synchronized double[][] uncompress(CompressRow compressRow) {
188188
}
189189
}
190190

191-
public void detach() {
191+
public void detach(IMatrixLayer topLayer) {
192192
this.rowsCache.invalidateAll();
193193
}
194194

org.gitools.matrix/src/main/java/org/gitools/matrix/model/mtabixmatrix/MTabixMatrix.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ public <T> void set(IMatrixLayer<T> layer, T value, String... identifiers) {
102102
super.set(layer, value, identifiers);
103103
}
104104

105-
public void detach() {
105+
public void detach(IMatrixLayer topLayer) {
106106

107107
//TODO improve evict policy
108-
for (LoadingCache<Long, MTabixBlockValues> cache : indexedCache.values()) {
109-
cache.invalidateAll();
108+
for (String layerKey : indexedCache.keySet()) {
109+
if (topLayer != null && !layerKey.equals(topLayer.getId())) {
110+
indexedCache.get(layerKey).invalidateAll();
111+
}
110112
}
111113

112114
}

org.gitools.ui.app/src/main/java/org/gitools/ui/app/heatmap/editor/HeatmapEditor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ public void run(IProgressMonitor monitor) {
452452
timer.cancel();
453453
timer.purge();
454454

455-
heatmap.detach();
455+
heatmap.detach(null);
456456

457457
if (heatmap.getData().getLocator() != null) {
458458
heatmap.getData().unload();
@@ -481,7 +481,7 @@ void mouseClicked(int row, int col, MouseEvent e) {
481481

482482
@Override
483483
public void detach() {
484-
this.heatmap.detach();
484+
this.heatmap.detach(heatmap.getLayers().getTopLayer());
485485
}
486486

487487
@Override

org.gitools.ui.app/src/main/java/org/gitools/ui/app/heatmap/panel/details/boxes/HeatmapInfoBox.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ public void update() {
9797
}
9898

9999
Heatmap heatmap = getHeatmap();
100-
this.setTitle(heatmap.getTitle());
101100

102101

103102
List<DetailsDecoration> details = new ArrayList<>();
@@ -119,19 +118,26 @@ public void update() {
119118
}
120119

121120
int rows = heatmap.getRows().size();
122-
int visibleRows = heatmap.getContents().getRows().size();
121+
int allRows = heatmap.getContents().getRows().size();
123122
int columns = heatmap.getColumns().size();
124-
int visibleColumns = heatmap.getContents().getColumns().size();
123+
int allColumns = heatmap.getContents().getColumns().size();
125124

126-
boolean showShownData = (rows != visibleRows || columns != visibleColumns);
125+
boolean showShownData = (rows != allRows || columns != allColumns);
127126

128-
DetailsDecoration alldata = new DetailsDecoration("Size (all data)", visibleRows + " x " + visibleColumns);
127+
DetailsDecoration alldata = new DetailsDecoration("Size (all data)", allRows + " x " + allColumns);
128+
129+
int rowsPct = (int) Math.round(((double) rows) / ((double) allRows) * 100.0);
130+
int colsPct = (int) Math.round(((double) columns) / ((double) allColumns) * 100.0);
129131

130132
if (showShownData) {
133+
this.setTitle("<html>" + heatmap.getTitle() + " ("
134+
+ rowsPct + "% x "
135+
+ colsPct + "%)</html>");
131136
DetailsDecoration shown = new DetailsDecoration("Size (shown)", rows + " x " + columns);
132137
shown.setSelected(true);
133138
details.add(shown);
134139
} else {
140+
this.setTitle("<html>" + heatmap.getTitle() + "</html>");
135141
alldata.setSelected(true);
136142
}
137143

org.gitools.ui.core/src/main/java/org/gitools/ui/core/components/editor/EditorsPanel.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ public void stateChanged(ChangeEvent evt) {
7272
}
7373

7474
refreshActions();
75+
76+
SwingUtilities.invokeLater(new Runnable() {
77+
@Override
78+
public void run() {
79+
System.gc();
80+
}
81+
});
7582
}
7683
});
7784
}

0 commit comments

Comments
 (0)