Ignore:
Timestamp:
2022-06-27T18:22:12+02:00 (2 years ago)
Author:
taylor.smock
Message:

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).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/AbstractMapRenderer.java

    r18332 r18501  
    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 18501
     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;
     
    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;
Note: See TracChangeset for help on using the changeset viewer.