Modify

#22106 closed defect (fixed)

[PATCH] Avoid allocations for point objects (Nodes) in QuadBuckets

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/QuadBuckets.java

    diff --git a/src/org/openstreetmap/josm/data/osm/QuadBuckets.java b/src/org/openstreetmap/josm/data/osm/QuadBuckets.java
    index 1f126bbb0b..916a1d048c 100644
    a b import java.util.NoSuchElementException;  
    1111import java.util.stream.IntStream;
    1212
    1313import org.openstreetmap.josm.data.IQuadBucketType;
     14import org.openstreetmap.josm.data.coor.ILatLon;
    1415import org.openstreetmap.josm.data.coor.LatLon;
    1516import org.openstreetmap.josm.data.coor.QuadTiling;
    1617import org.openstreetmap.josm.tools.Logging;
    public class QuadBuckets<T extends IQuadBucketType> implements Collection<T> {  
    173174        }
    174175
    175176        boolean matches(final T o, final BBox searchBbox) {
     177            // Avoid allocations for point (AKA Node) objects
     178            if (o instanceof ILatLon) {
     179                return searchBbox.contains((ILatLon) o);
     180            }
    176181            return o.getBBox().intersects(searchBbox);
    177182        }
    178183

This reduces the allocations for Nodes in QuadBuckets.QBLevel#matches by 80% (we're no longer creating a new BBox every time). The remaining cost is from ArrayList#grow.

Unfortunately, this isn't a major perf win (it is dwarfed by other things) but it does shave a percentage point or two off of the render path allocations.

Attachments (0)

Change History (2)

comment:1 by taylor.smock, 23 months ago

Milestone: 22.06

comment:2 by taylor.smock, 23 months ago

Resolution: fixed
Status: newclosed

In 18465/josm:

Fix #22106: Avoid allocations for point objects in QuadBuckets

Nodes do not keep their bboxes in memory (to reduce overall memory usage).
This does mean that every time someone searches a quadbucket for nodes, we
have to recreate the BBox for every node in a quadbucket leaf. This is a
significant number of allocations that are unnecessary (~80% of the memory
allocations from QuadBuckets#search for nodes is from the creation of
temporary bboxes). The remaining cost for the search is from List#grow calls.

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.