Modify

Opened 3 years ago

Closed 3 years ago

#20830 closed enhancement (fixed)

Reduce heap size of org.openstreetmap.josm.data.osm.Node by 8 bytes

Reported by: simon04 Owned by: simon04
Priority: normal Milestone: 21.05
Component: Core Version:
Keywords: heap profiling intellij yourkit Cc:

Description

We can save 8 bytes for each org.openstreetmap.josm.data.osm.Node instance by moving the mappaintCacheIdx from OsmPrimitive to AbstractPrimitive due to Java's memory layout alignment.

BEFORE org.openstreetmap.josm.data.osm.Node object internals:
 OFFSET  SIZE         TYPE DESCRIPTION                               VALUE
      0    16              (object header)                           N/A
     16     8         long AbstractPrimitive.id                      N/A
     24     4          int AbstractPrimitive.version                 N/A
     28     4          int AbstractPrimitive.changesetId             N/A
     32     4          int AbstractPrimitive.timestamp               N/A
     36     2        short AbstractPrimitive.flags                   N/A
     38     2              (alignment/padding gap)                  
     40     8         User AbstractPrimitive.user                    N/A
     48     8     String[] AbstractPrimitive.keys                    N/A
     56     2        short OsmPrimitive.mappaintCacheIdx             N/A
     58     6              (alignment/padding gap)                  
     64     8   StyleCache OsmPrimitive.mappaintStyle                N/A
     72     8      DataSet OsmPrimitive.dataSet                      N/A
     80     8       Object OsmPrimitive.referrers                    N/A
     88     8       double Node.lat                                  N/A
     96     8       double Node.lon                                  N/A
    104     8       double Node.east                                 N/A
    112     8       double Node.north                                N/A
    120     8       Object Node.eastNorthCacheKey                    N/A
Instance size: 128 bytes
Space losses: 8 bytes internal + 0 bytes external = 8 bytes total
  • src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java

    diff --git a/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java b/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
    index 591048789..47262617a 100644
    a b public abstract class AbstractPrimitive implements IPrimitive {  
    135135     */
    136136    protected volatile short flags = FLAG_VISIBLE;   // visible per default
    137137
     138    /**
     139     * The mappaint cache index for this primitive.
     140     * This field belongs to {@code OsmPrimitive}, but due to Java's memory layout alignment
     141     */
     142    protected short mappaintCacheIdx;
     143
    138144    /*-------------------
    139145     * OTHER PROPERTIES
    140146     *-------------------*/
  • src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    diff --git a/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java b/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
    index 764e4e1d3..496751f98 100644
    a b public abstract class OsmPrimitive extends AbstractPrimitive implements Template  
    145145     * MAPPAINT
    146146     *--------*/
    147147    private StyleCache mappaintStyle;
    148     private short mappaintCacheIdx;
    149148
    150149    @Override
    151150    public final StyleCache getCachedStyle() {
AFTER org.openstreetmap.josm.data.osm.Node object internals:
 OFFSET  SIZE         TYPE DESCRIPTION                               VALUE
      0    16              (object header)                           N/A
     16     8         long AbstractPrimitive.id                      N/A
     24     4          int AbstractPrimitive.version                 N/A
     28     4          int AbstractPrimitive.changesetId             N/A
     32     4          int AbstractPrimitive.timestamp               N/A
     36     2        short AbstractPrimitive.flags                   N/A
     38     2        short AbstractPrimitive.mappaintCacheIdx        N/A
     40     8         User AbstractPrimitive.user                    N/A
     48     8     String[] AbstractPrimitive.keys                    N/A
     56     8   StyleCache OsmPrimitive.mappaintStyle                N/A
     64     8      DataSet OsmPrimitive.dataSet                      N/A
     72     8       Object OsmPrimitive.referrers                    N/A
     80     8       double Node.lat                                  N/A
     88     8       double Node.lon                                  N/A
     96     8       double Node.east                                 N/A
    104     8       double Node.north                                N/A
    112     8       Object Node.eastNorthCacheKey                    N/A
Instance size: 120 bytes
Space losses: 0 bytes internal + 0 bytes external = 0 bytes total

Attachments (0)

Change History (1)

comment:1 by simon04, 3 years ago

Resolution: fixed
Status: assignedclosed

In 17849/josm:

fix #20830 - Reduce heap size of org.openstreetmap.josm.data.osm.Node by 8 bytes

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain simon04.
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.