Skip to content

Avoid creating unnecessary images in tile layers #3246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 19, 2015
Merged

Avoid creating unnecessary images in tile layers #3246

merged 2 commits into from
Feb 19, 2015

Conversation

tschaub
Copy link
Member

@tschaub tschaub commented Feb 16, 2015

When rendering tiled layers, we call source.getTile() many times while looking for loaded images at alternate zoom levels. For image tile layers, calls to getTile create Image elements. When we only need to check if a tile is loaded, it is unnecessary to create a new tile with an unused Image.

Since all of the ol.source.Tile types create a tile cache in the same way and have the same implementation of canExpireCache and expireCache, we can move the repeated code to the ol.source.Tile base class (see 2cf1fe5).

Then, since an image cannot already have the loaded state if it is not in the cache, the check for loaded images can avoid calling getTile and instead check the cache (see e5432f7). The DOM and Canvas tile layer renderers can share the same implementation of createLoadedTileFinder function. The WebGL renderer needs a custom implementation since it also checks with the map renderer to see if the tile texture is loaded.

Without these changes, the first rendering of the full screen example (not in full screen mode) fills the cache with 80 images though only 12 are used (on my current screen width). And these extra cached images are not used as you zoom out. By the time I zoom out to level one, about 1350 Image elements have been created. On this branch, the same sequence (zooming one step at a time to level 1) creates 350 Image elements.

@tschaub tschaub changed the title Create tile cache for all tile sources Avoid creating unnecessary images in tile layers Feb 16, 2015
@ahocevar
Copy link
Member

This is a huge performance improvement and greatly improves code readability. I'm very impressed and +1 on merging this!

tschaub added a commit that referenced this pull request Feb 19, 2015
Avoid creating unnecessary images in tile layers.
@tschaub tschaub merged commit 733167c into openlayers:master Feb 19, 2015
@tschaub tschaub deleted the tile-cache branch February 19, 2015 17:33
@elemoine
Copy link
Member

Very nice!

Shouldn't the createGetTileIfLoadedFunction function be removed?

@tschaub
Copy link
Member Author

tschaub commented Feb 24, 2015

Shouldn't the createGetTileIfLoadedFunction function be removed?

Yes, thanks. That was an oversight (see #3273).

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.

3 participants