Modify

Opened 3 years ago

Closed 3 years ago

#22139 closed defect (fixed)

[PATCH] Significantly reduce allocations in NodeElement

Reported by: taylor.smock Owned by: team
Priority: normal Milestone: 22.06
Component: Core Version:
Keywords: performance Cc:

Description (last modified by taylor.smock)

  • 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;  
    77import java.awt.Stroke;
    88import java.util.Objects;
    99import java.util.Optional;
    10 import java.util.stream.IntStream;
    1110
    1211import org.openstreetmap.josm.data.osm.INode;
    1312import org.openstreetmap.josm.data.osm.IPrimitive;
    public class NodeElement extends StyleElement {  
    350349        }
    351350    }
    352351
    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)));
    355360    }
    356361
    357362    @Override

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

Attachments (0)

Change History (4)

comment:1 by taylor.smock, 3 years ago

Description: modified (diff)

comment:2 by taylor.smock, 3 years ago

Description: modified (diff)
Summary: [PATCH] Significantly reduce allocations in NodeElement and StyledMapRenderer[PATCH] Significantly reduce allocations in NodeElement

comment:3 by taylor.smock, 3 years ago

Description: modified (diff)

comment:4 by taylor.smock, 3 years ago

Resolution: fixed
Status: newclosed

In 18502/josm:

Fix #22139: Significantly reduce allocations in NodeElement

This significantly reduces the cost for painting nodes.
In testing (Mesa County, Colorado, downloaded via overpass),
this reduces the cost for painting nodes (no paintstyle) by
66% (memory allocations) and ~17% (CPU allocations).

This comes out to about 7% of CPU cycles during map paint and
~20% of memory allocations during map paint.

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.