Changeset 8659 in josm for trunk


Ignore:
Timestamp:
2015-08-12T23:10:17+02:00 (9 years ago)
Author:
wiktorn
Message:

More performance improvements

  • Use one MemoryTileCache instance per multiple layers. This results in smaller memory footprint when working with many layers
  • fix default maximum TimeToLive in JCS
  • TemplatedWMSTileSource now caches degreesPerZoom, so it's not computed on every request
Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java

    r8624 r8659  
    3939
    4040    private static volatile CompositeCacheManager cacheManager = null;
    41     private static long maxObjectTTL        = Long.MAX_VALUE;
     41    private static long maxObjectTTL        = -1;
    4242    private static final String PREFERENCE_PREFIX = "jcs.cache";
    4343    private static final AuxiliaryCacheFactory diskCacheFactory = new IndexedDiskCacheFactory();
  • trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java

    r8652 r8659  
    4343    private int[] tileXMax;
    4444    private int[] tileYMax;
     45    private double[] degreesPerTile;
    4546
    4647    private static final Pattern PATTERN_HEADER  = Pattern.compile("\\{header\\(([^,]+),([^}]+)\\)\\}");
     
    9596        tileXMax = new int[getMaxZoom() + 1];
    9697        tileYMax = new int[getMaxZoom() + 1];
     98        degreesPerTile = new double[getMaxZoom() +1];
    9799        for (int zoom = getMinZoom(); zoom <= getMaxZoom(); zoom++) {
    98100            TileXY maxTileIndex = latLonToTileXY(bottomRight.toCoordinate(), zoom);
    99101            tileXMax[zoom] = maxTileIndex.getXIndex();
    100102            tileYMax[zoom] = maxTileIndex.getYIndex();
    101         }
     103            int tilesPerZoom = (int) Math.pow(2d, zoom - 1);
     104            degreesPerTile[zoom] = Math.max(
     105                    Math.abs(max.getY() - min.getY()) / tilesPerZoom,
     106                    Math.abs(max.getX() - min.getX()) / tilesPerZoom
     107                    );
     108
     109        }
     110
    102111    }
    103112
     
    382391
    383392    private double getDegreesPerTile(int zoom) {
    384         Projection proj = Main.getProjection();
    385         EastNorth min = proj.latlon2eastNorth(worldBounds.getMin());
    386         EastNorth max = proj.latlon2eastNorth(worldBounds.getMax());
    387 
    388         int tilesPerZoom = (int) Math.pow(2d, zoom - 1);
    389         return Math.max(
    390                 Math.abs(max.getY() - min.getY()) / tilesPerZoom,
    391                 Math.abs(max.getX() - min.getX()) / tilesPerZoom
    392                 );
     393        return degreesPerTile[zoom];
    393394    }
    394395
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractCachedTileSourceLayer.java

    r8647 r8659  
    3636     */
    3737    public static final IntegerProperty MAX_DISK_CACHE_SIZE = new IntegerProperty(PREFERENCE_PREFIX + "max_disk_size", 512);
    38 
    39     /**
    40      * use fairly small memory cache, as cached objects are quite big, as they contain BufferedImages
    41      */
    42     public static final IntegerProperty MEMORY_CACHE_SIZE = new IntegerProperty(PREFERENCE_PREFIX + "cache.max_objects_ram", 200);
    4338
    4439    private ICacheAccess<String, BufferedImageCacheEntry> cache;
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r8648 r8659  
    134134    public boolean showErrors;
    135135
    136     protected TileCache tileCache;
     136    /**
     137     * use fairly small memory cache, as cached objects are quite big, as they contain BufferedImages
     138     */
     139    public static final IntegerProperty MEMORY_CACHE_SIZE = new IntegerProperty(PREFERENCE_PREFIX + "cache.max_objects_ram", 200);
     140
     141    /*
     142     *  use MemoryTileCache instead of tileLoader JCS cache, as tileLoader caches only content (byte[] of image)
     143     *  and MemoryTileCache caches whole Tile. This gives huge performance improvement when a lot of tiles are visible
     144     *  in MapView (for example - when limiting min zoom in imagery)
     145     *
     146     *  Use static instance so memory is shared between layers to prevent out of memory exceptions, when user is working with many layers
     147     */
     148    protected static TileCache tileCache = new MemoryTileCache(MEMORY_CACHE_SIZE.get());
    137149    protected AbstractTMSTileSource tileSource;
    138150    protected TileLoader tileLoader;
     
    174186
    175187        tileLoader = getTileLoaderFactory().makeTileLoader(this, headers);
    176         /*
    177          *  use MemoryTileCache instead of tileLoader JCS cache, as tileLoader caches only content (byte[] of image)
    178          *  and MemoryTileCache caches whole Tile. This gives huge performance improvement when a lot of tiles are visible
    179          *  in MapView (for example - when limiting min zoom in imagery)
    180          */
    181         tileCache = new MemoryTileCache(AbstractCachedTileSourceLayer.MEMORY_CACHE_SIZE.get());
    182188
    183189        try {
Note: See TracChangeset for help on using the changeset viewer.