Skip to content

TileLayer retains cache on data change - #6194

Merged
Pessimistress merged 15 commits into
masterfrom
ig/maintain_layer_on_update_trigger
Oct 1, 2021
Merged

Pessimistress merged 15 commits into
masterfrom
ig/maintain_layer_on_update_trigger

Conversation

@ilan-gold

Copy link
Copy Markdown
Collaborator

Fixes #6179

Change List

  • Add a reload method for Tileset2D to be called on updates by updateTriggers instead of creating a new tileset

@ilan-gold ilan-gold left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments.

Comment on lines +88 to +89
// Should we do the same as the above? Not delete but use a boolean to cause an update?
tileset.tiles.forEach(tile => {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pessimistress Not sure what the origin of this behavior was but seems similar to the above? We should just set them to have updateLayers be true


_updateTileset() {
const {tileset} = this.state;
_updateTileset(tileset, reload = false) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to just setting up a new method but it feels like it would need to look similar i.e change frame number, check loading, call onViewportLoad etc.

Comment on lines +62 to +64
loadOptions(opts) {
this._loadOptions(opts);
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already a setOptions function - should these be merged?

/* eslint-enable complexity */

_getTile({x, y, z}, create) {
_getTile({x, y, z}, create, reload) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better way to do forced reloads?

@ilan-gold
ilan-gold marked this pull request as draft September 13, 2021 19:49
@ilan-gold

Copy link
Copy Markdown
Collaborator Author

Also, the requestScheduler appears to be hanging. Whenever I comment out all the bits about it, the tests pass (obviously the Tile2DHeader tests fail though).

@ilan-gold

ilan-gold commented Sep 14, 2021 •

Copy link
Copy Markdown
Collaborator Author

This is what I was talking about with the scheduler - I just pushed a change with some debugging changes. I log out before and after the scheduler is called, and then look at the output:

# Custom getTileData
waiting for request token!
waiting for request token!
ok 4134 Rendered sublayers
not ok 4135 Fetched tile data
  ---
    operator: equal
    expected: 2
    actual:   0
    at: Object.onAfterUpdate (/Users/ilan_gold/deck.gl/test/modules/geo-layers/tile-layer/tile-layer.spec.js:99:13)
    stack: |-
      Error: Fetched tile data
          at Test.assert [as _assert] (/Users/ilan_gold/deck.gl/node_modules/tape/lib/test.js:228:54)
          at Test.bound [as _assert] (/Users/ilan_gold/deck.gl/node_modules/tape/lib/test.js:80:32)
          at Test.equal (/Users/ilan_gold/deck.gl/node_modules/tape/lib/test.js:389:10)
          at Test.is (/Users/ilan_gold/deck.gl/node_modules/tape/lib/test.js:80:32)
          at Object.onAfterUpdate (/Users/ilan_gold/deck.gl/test/modules/geo-layers/tile-layer/tile-layer.spec.js:99:13)
          at runLayerTestPostUpdateCheck (/Users/ilan_gold/deck.gl/modules/test-utils/src/lifecycle-test.js:187:14)
          at testLayerAsync (/Users/ilan_gold/deck.gl/modules/test-utils/src/lifecycle-test.js:103:5)
          at Test.<anonymous> (/Users/ilan_gold/deck.gl/test/modules/geo-layers/tile-layer/tile-layer.spec.js:168:3)
  ...
ok 4136 Layer is loaded
ok 4137 Sublayers at z=2 are visible
waiting for request token!
waiting for request token!
got request token!
got request token!
got request token!
got request token!

(Assuming the logging is right) The tokens come back after the tests. But this isn't the case on the current master branch so there must be something going on here that I'm missing:

# Custom getTileData
waiting for request token!
waiting for request token!
ok 4136 should be truthy
got request token!
got request token!
ok 4137 Rendered sublayers
ok 4138 Fetched tile data
ok 4139 Layer is loaded
ok 4140 Sublayers at z=2 are visible

One thing I notice is that

onAfterUpdate: ({layer, subLayers}) => {
if (!layer.isLoaded) {
t.ok(subLayers.length < 2);
} else {
is being called on master and not this branch...

@Pessimistress
Pessimistress force-pushed the ig/maintain_layer_on_update_trigger branch from 60d11ac to 272293b Compare September 20, 2021 22:12
@Pessimistress

Pessimistress commented Sep 20, 2021 •

Copy link
Copy Markdown
Collaborator

@ilan-gold I pushed a different approach:

  • Tile2DHeader.loadData can be called multiple times and the result from the last call is used
  • Tileset2D.reloadAll flags all cached tiles as needs reload
  • When a tile is selected during Tileset2D.update, call tile.loadData if it's flagged as needs reload

Also made some internal API changes to tile.loadData to improve readability. Unit tests are updated to reflect this API change.

deck gl-tile-reload

@ilan-gold

Copy link
Copy Markdown
Collaborator Author

Screen Shot 2021-09-29 at 3 33 00 PM
Changing channels (i.e updateTriggers) too quickly yields this result. I'll look into it.

@Pessimistress
Pessimistress force-pushed the ig/maintain_layer_on_update_trigger branch from 272293b to c5637d3 Compare September 30, 2021 08:27
@Pessimistress Pessimistress changed the title updateTriggers and TileLayer Fix TileLayer retains cache on data change Sep 30, 2021
@coveralls

coveralls commented Sep 30, 2021 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.04%) to 81.925% when pulling 2790a2c on ig/maintain_layer_on_update_trigger into 60e9334 on master.

Comment on lines +112 to +115
reloadAll() {
for (const tile of this._cache.values()) {
tile.setNeedsReload();
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it makes sense to have two different loops here, one for reloading _selectedTiles i.e those in the viewport, and then another for clearing the cache of those outside the viewport? For example if you zoom out after the load has occurred, you will get old tiles sometimes. I think it would be better to have just no tiles outside the viewport instead of old data. I think that was the idea originally with my (very bad) code: 8f4cdd2#diff-ebfc47135e3d8fe2bee8b3d33fae4ebbbc295d01887c751d4cb77f71fc85a87aR70-R77

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reloadAll() {
for (const tile of this._cache.values()) {
tile.setNeedsReload();
}
reloadAll() {
for (const [tileId, tile] of this._cache) {
if (!this._selectedTiles.includes(tile)) {
this._cache.delete(tileId);
} else {
tile.setNeedsReload();
}
}

Something like this maybe?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the proposed behavior makes sense. Feel free to push a commit.

I'm always a little wary about deleting items in a traversal. for (const tileId of this._cache.keys()) maybe?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated!

@ilan-gold
ilan-gold marked this pull request as ready for review October 1, 2021 03:35
@Pessimistress
Pessimistress merged commit 9b26369 into master Oct 1, 2021
@Pessimistress
Pessimistress deleted the ig/maintain_layer_on_update_trigger branch October 1, 2021 21:45
@ilan-gold ilan-gold mentioned this pull request Oct 12, 2021
1 of 2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TileLayer Update Triggers

3 participants