Skip to content

Commit 85b28a3

Browse files
author
taylor.smock
committed
Fix #23908: Significantly improve the performance of copy/paste when dealing with large amounts of data
From #23908, at least one valid workflow involves copy/pasting large amounts of data (specifically updating boundaries). The relation for `Terwolde` in the sample data had 2206 objects. This took >5 minutes to copy between layers. With this change, it takes <1 second. This is a performance regression from r19176. The primary culprit from r19176 is when we check the size of the dataset. The problem is that we check to see if the size of the primitives being changed is greater than or equal to the non-deleted complete primitives in the dataset. We get a new filtered collection each time we get those primitives, and therefore the size of that is not cached. The size calculation for the filtered collection is where almost all the expense is. We fix that by wrapping the work from AddPrimitivesCommand in `DataSet#update` to have a single large update at the end of the copy operation. This ensures that we do not have many spurious fired event calls when a mass operation is going on. git-svn-id: https://josm.openstreetmap.de/svn/trunk@19214 0c6e7542-c601-0410-84e7-c038aed88b3b
1 parent 8d42e3f commit 85b28a3

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/org/openstreetmap/josm/command/AddPrimitivesCommand.java

+8-11
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import java.util.Optional;
1111
import java.util.stream.Collectors;
1212

13-
import javax.swing.Icon;
14-
1513
import org.openstreetmap.josm.data.osm.DataSet;
1614
import org.openstreetmap.josm.data.osm.Node;
1715
import org.openstreetmap.josm.data.osm.NodeData;
@@ -68,6 +66,14 @@ private void init(List<PrimitiveData> data, List<PrimitiveData> toSelect) {
6866
@Override
6967
public boolean executeCommand() {
7068
DataSet ds = getAffectedDataSet();
69+
ds.update(() -> this.executeRealCommand(ds));
70+
if (toSelect != null) {
71+
ds.setSelected(toSelect.stream().map(ds::getPrimitiveById).collect(Collectors.toList()));
72+
}
73+
return true;
74+
}
75+
76+
private void executeRealCommand(DataSet ds) {
7177
if (createdPrimitives == null) { // first time execution
7278
List<OsmPrimitive> newPrimitives = new ArrayList<>(data.size());
7379
preExistingData = new ArrayList<>();
@@ -109,10 +115,6 @@ public boolean executeCommand() {
109115
}
110116
}
111117
}
112-
if (toSelect != null) {
113-
ds.setSelected(toSelect.stream().map(ds::getPrimitiveById).collect(Collectors.toList()));
114-
}
115-
return true;
116118
}
117119

118120
@Override public void undoCommand() {
@@ -148,11 +150,6 @@ public String getDescriptionText() {
148150
return trn("Added {0} object", "Added {0} objects", size, size);
149151
}
150152

151-
@Override
152-
public Icon getDescriptionIcon() {
153-
return null;
154-
}
155-
156153
@Override
157154
public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
158155
Collection<OsmPrimitive> added) {

0 commit comments

Comments
 (0)