Modify

#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 {  
    213213     * @param p1 First point of the way segment.
    214214     * @param p2 Second point of the way segment.
    215215     * @return <code>true</code> if segment may be visible.
     216     * @see #isSegmentVisible(MapViewPoint, MapViewPoint, MapViewRectangle) for a more efficient version (cache the view)
    216217     * @since 10827
    217218     */
    218219    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) {
    220233        // not outside in the same direction
    221234        return (p1.getOutsideRectangleFlags(view) & p2.getOutsideRectangleFlags(view)) == 0;
    222235    }
    public abstract class AbstractMapRenderer implements Rendering {  
    232245    public void visitVirtual(Path2D path, IWay<?> w) {
    233246        Iterator<? extends INode> it = w.getNodes().iterator();
    234247        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();
    235252        while (it.hasNext()) {
    236253            INode n = it.next();
    237254            if (n.isLatLonKnown()) {
    238255                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)) {
    240257                    double x = (p.getInViewX()+lastP.getInViewX())/2;
    241258                    double y = (p.getInViewY()+lastP.getInViewY())/2;
    242259                    path.moveTo(x-virtualNodeSize, y);

I'm planning on applying this Monday, June 20th.

Attachments (0)

Change History (2)

comment:1 by taylor.smock, 23 months ago

Milestone: 22.06

comment:2 by taylor.smock, 22 months ago

Resolution: fixed
Status: newclosed

In 18501/josm:

Fix #22140: Significantly reduce allocations in AbstractMapRenderer#drawVirtualNodes

This reduces MapViewState#getViewArea from ~56.5% of memory allocations to ~4.2%.
This also reduced the CPU samples for that method from 5.1% to 2.9%.
The profiling occurred with Mesa County, Colorado downloaded (via overpass).

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.