Skip to content

Commit d91105d

Browse files
authored
Adjust the lru unload function (#651)
1 parent 75b8283 commit d91105d

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/base/TilesRendererBase.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,26 @@ const priorityCallback = ( a, b ) => {
4848

4949
};
5050

51-
/**
52-
* Function for sorting the evicted LRU items. We should evict the shallowest depth first.
53-
* @param {Tile} tile
54-
* @returns number
55-
*/
51+
// lru cache unload callback that takes two tiles to compare
5652
const lruPriorityCallback = ( a, b ) => {
5753

58-
const aVal = 1 / ( a.__depthFromRenderedParent + 1 );
59-
const bVal = 1 / ( b.__depthFromRenderedParent + 1 );
60-
if ( aVal < bVal ) return - 1;
61-
if ( aVal > bVal ) return 1;
54+
if ( a.__depthFromRenderedParent !== b.__depthFromRenderedParent ) {
55+
56+
// dispose of deeper tiles first
57+
return a.__depthFromRenderedParent > b.__depthFromRenderedParent ? 1 : - 1;
58+
59+
} else if ( a.__lastFrameVisited !== b.__lastFrameVisited ) {
60+
61+
// dispose of least recent tiles first
62+
return a.__lastFrameVisited > b.__lastFrameVisited ? - 1 : 1;
63+
64+
} else if ( a.__externalTileSet !== b.__externalTileSet ) {
65+
66+
// dispose of external tile sets last
67+
return a.__externalTileSet ? - 1 : 1;
68+
69+
}
70+
6271
return 0;
6372

6473
};

0 commit comments

Comments
 (0)