Modify ↓
Opened 23 months ago
Closed 22 months ago
#22140 closed enhancement (fixed)
[PATCH] Significantly reduce allocations in AbstractMapRenderer#drawVirtualNodes
Reported by: | taylor.smock | Owned by: | team |
---|---|---|---|
Priority: | normal | Milestone: | 22.06 |
Component: | Core | Version: | |
Keywords: | performance | Cc: |
Description
-
src/org/openstreetmap/josm/data/osm/visitor/paint/AbstractMapRenderer.java
diff --git a/src/org/openstreetmap/josm/data/osm/visitor/paint/AbstractMapRenderer.java b/src/org/openstreetmap/josm/data/osm/visitor/paint/AbstractMapRenderer.java index 1d00a63aad..68b8a1262e 100644
a b public abstract class AbstractMapRenderer implements Rendering { 213 213 * @param p1 First point of the way segment. 214 214 * @param p2 Second point of the way segment. 215 215 * @return <code>true</code> if segment may be visible. 216 * @see #isSegmentVisible(MapViewPoint, MapViewPoint, MapViewRectangle) for a more efficient version (cache the view) 216 217 * @since 10827 217 218 */ 218 219 protected boolean isSegmentVisible(MapViewPoint p1, MapViewPoint p2) { 219 MapViewRectangle view = mapState.getViewArea(); 220 return isSegmentVisible(p1, p2, mapState.getViewArea()); 221 } 222 223 /** 224 * Checks if segment is visible in display. 225 * 226 * @param p1 First point of the way segment. 227 * @param p2 Second point of the way segment. 228 * @param view The current view to check 229 * @return <code>true</code> if segment may be visible. 230 * @since xxx 231 */ 232 protected boolean isSegmentVisible(MapViewPoint p1, MapViewPoint p2, MapViewRectangle view) { 220 233 // not outside in the same direction 221 234 return (p1.getOutsideRectangleFlags(view) & p2.getOutsideRectangleFlags(view)) == 0; 222 235 } … … public abstract class AbstractMapRenderer implements Rendering { 232 245 public void visitVirtual(Path2D path, IWay<?> w) { 233 246 Iterator<? extends INode> it = w.getNodes().iterator(); 234 247 MapViewPoint lastP = null; 248 // By moving this out of the for loop (in isSegmentVisible) 249 // MapViewState#getViewArea goes from ~56.5% of memory allocations to ~4.2% 250 // CPU samples also goes down from ~5.1% to ~2.9% 251 MapViewRectangle viewArea = mapState.getViewArea(); 235 252 while (it.hasNext()) { 236 253 INode n = it.next(); 237 254 if (n.isLatLonKnown()) { 238 255 MapViewPoint p = mapState.getPointFor(n); 239 if (lastP != null && isSegmentVisible(lastP, p ) && isLargeSegment(lastP, p, virtualNodeSpace)) {256 if (lastP != null && isSegmentVisible(lastP, p, viewArea) && isLargeSegment(lastP, p, virtualNodeSpace)) { 240 257 double x = (p.getInViewX()+lastP.getInViewX())/2; 241 258 double y = (p.getInViewY()+lastP.getInViewY())/2; 242 259 path.moveTo(x-virtualNodeSize, y);
I'm planning on applying this Monday, June 20th.
Attachments (0)
Change History (2)
comment:1 by , 23 months ago
Milestone: | → 22.06 |
---|
comment:2 by , 22 months ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
In 18501/josm: