Opened 4 years ago
Last modified 4 years ago
#22139 closed defect
[PATCH] Significantly reduce allocations in NodeElement and StyledMapRenderer — at Version 1
| Reported by: | taylor.smock | Owned by: | team |
|---|---|---|---|
| Priority: | normal | Milestone: | 22.06 |
| Component: | Core | Version: | |
| Keywords: | performance | Cc: |
Description (last modified by )
-
src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
diff --git a/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java b/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java index b27acb4bc5..2e49c30ca5 100644
a b import org.openstreetmap.josm.data.osm.IPrimitive; 52 52 import org.openstreetmap.josm.data.osm.IRelation; 53 53 import org.openstreetmap.josm.data.osm.IRelationMember; 54 54 import org.openstreetmap.josm.data.osm.IWay; 55 import org.openstreetmap.josm.data.osm.Node; 55 56 import org.openstreetmap.josm.data.osm.OsmData; 56 57 import org.openstreetmap.josm.data.osm.OsmPrimitive; 57 58 import org.openstreetmap.josm.data.osm.OsmUtils; … … public class StyledMapRenderer extends AbstractMapRenderer { 754 755 if (size <= 0 && !n.isHighlighted()) 755 756 return; 756 757 757 MapViewPoint p = mapState.getPointFor(n); 758 // This reduces memory usage for StyledMapRenderer#paintWithLock from 5.1% to 1.2% 759 // and slightly reduces CPU usage. 760 MapViewPoint p = n instanceof Node ? mapState.getPointFor((Node) n) : mapState.getPointFor(n); 758 761 759 762 if (n.isHighlighted()) { 760 763 drawPointHighlight(p.getInView(), size); -
src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java
diff --git a/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java b/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java index 69b05c84b6..2b6852d7ba 100644
a b import java.awt.Rectangle; 7 7 import java.awt.Stroke; 8 8 import java.util.Objects; 9 9 import java.util.Optional; 10 import java.util.stream.IntStream;11 10 12 11 import org.openstreetmap.josm.data.osm.INode; 13 12 import org.openstreetmap.josm.data.osm.IPrimitive; … … public class NodeElement extends StyleElement { 350 349 } 351 350 } 352 351 353 private static int max(int... elements) { 354 return IntStream.of(elements).max().orElseThrow(IllegalStateException::new); 352 private static int max(int a, int b, int c, int d) { 353 // Profile before switching to a stream/int[] array 354 // This was 66% give or take for painting nodes in terms of memory allocations 355 // and was ~17% of the CPU allocations. By not using a vararg method call, we avoid 356 // the creation of an array. By avoiding both streams and arrays, the cost for this method is negligible. 357 // This means that this saves about 7% of the CPU cycles during map paint, and about 20% 358 // of the memory allocations during map paint. 359 return Math.max(a, Math.max(b, Math.max(c, d))); 355 360 } 356 361 357 362 @Override
Note:
See TracTickets
for help on using tickets.


