Changeset 17516 in josm


Ignore:
Timestamp:
2021-02-21T23:50:53+01:00 (10 days ago)
Author:
wiktorn
Message:

Fine tune cache sizing

Reduce the cache size, by not counting the tiles that are overloaded for other
zoom levels. Overloaded tiles are only counted for current zoom level.

This reduces memory requirements for a layer, depending on the number of the
tiles shown by 20%-50%. Reduction is high for low number of tiles (when large
tiles or small screen is in use) and low for high number of tiles (when
small tiles or large screen is in use)

See: #20014, #20497

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r17509 r17516  
    641641        /**
    642642         * As we can see part of the tile at the top and at the bottom, use Math.ceil(...) + 1 to accommodate for that
    643          * Add another 2 tiles on each axis, as overloadTiles adds one tile in each direction that might be overloaded
    644          *
    645          * @see #overloadTiles()
    646643         */
    647         int maxYtiles = (int) Math.ceil((double) height / tileSize + 1) + 2;
    648         int maxXtiles = (int) Math.ceil((double) width / tileSize + 1) + 2;
     644        int maxYtiles = (int) Math.ceil((double) height / tileSize + 1);
     645        int maxXtiles = (int) Math.ceil((double) width / tileSize + 1);
    649646        int visibileTiles = maxXtiles * maxYtiles;
    650647        /**
    651          * Take into account ZOOM_OFFSET to calculate real number of tiles and multiply by 8, to cover all tiles, that might be
     648         * Take into account ZOOM_OFFSET to calculate real number of tiles and multiply by 7, to cover all tiles, that might be
    652649         * accessed when looking for tiles outside current zoom level.
    653650         *
    654          * The value should be sum(2^x for x in (-5 to 2))
     651         * Currently we use otherZooms = {1, 2, -1, -2, -3, -4, -5}
    655652         *
    656          * Currently we use otherZooms = {1, 2, -1, -2, -3, -4, -5}
     653         * The value should be sum(2^x for x in (-5 to 2)) - 1
     654         * -1 to exclude current zoom level
    657655         *
    658656         * Check call to tryLoadFromDifferentZoom
     
    660658         * @see #drawInViewArea((Graphics2D, MapView, ProjectionBounds)
    661659         *
     660         * Add +2 to maxYtiles / maxXtiles to add space in cache for extra tiles in current zoom level that are
     661         * download by overloadTiles(). This is not added in computation of visibileTiles as this unnecessarily grow the cache size
     662         * @see #overloadTiles()
    662663         */
    663664        int ret = (int) Math.ceil(
    664                 Math.pow(2d, ZOOM_OFFSET.get()) * visibileTiles // use offset to decide, how many tiles are visible
    665                 * 8);
    666         Logging.info("AbstractTileSourceLayer: estimated tiles proccessed on current zoom level: {0}, estimated cache size: {1}",
    667                 visibileTiles, ret);
     665                Math.pow(2d, ZOOM_OFFSET.get()) * // use offset to decide, how many tiles are visible
     666                visibileTiles * 7 + // 7 to cover tiles from other zooms as described above
     667                ((maxYtiles + 2) * (maxXtiles +2))); // to add as many tiles as they will be accessed on current zoom level
     668        Logging.info("AbstractTileSourceLayer: estimated visibile tiles: {0}, estimated cache size: {1}", visibileTiles, ret);
    668669        return ret;
    669670    }
Note: See TracChangeset for help on using the changeset viewer.