You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
UI interactions should be smooth, independent of tile loadings in the background.
Actual Behavior
The UX is really bad with raster layers now. Chrome FPS meter regularly gets under 2.0 fps on my Macbook Pro.
I've almost finished porting a big codebase over to Mapbox GL viewer, but this one is puzzling me. Both Leaflet and OpenLayers can display raster maps at constant 58+ FPS. How is it possible that Mapbox GL can render the most complicated vector tile regions smoothly, but is breaking with simple raster tiles?
This seems to be some kind of regression with the source cache logic — most of the time is spend figuring out which tiles to show, not actual rendering or loading. Investigating now.
Looks like it's not a regression, just an algorithm that dramatically slows down quadratically when the tile size goes down — it was only optimized for vector tiles, where you typically only see 6-7 tiles on the screen. Thinking about a faster one now...
Turns out that the jank on raster layers is currently dominated by XHR requests, which we use to load images since #1472 because of an issue with browsers not fully respecting Cache-Control: no-cache (#1470). You can see how much snappier the raster test case becomes in 9b372d9, which uses the old image loading approach (git co bench-raster-tile-load, yarn run start-debug, then load http://localhost:9966/debug/). If you switch getImage back to XHR-based requests in ajax.js, it becomes unusably janky, as reported.
Since the original fix with XHR image loads was introduced specifically to fix sprite updates, and most image loads don't have short cache spans, I wonder if we can use some kind of a mixed approach. For example, a raster tile source would do its first request with XHR-based getImage, see if cacheControl is small (no-cache, small enough max-age or whatever), and then either continue using XHR or switch to simple new Image for snappier performance. @jfirebaugh what do you think?
Thanks, it's great to see this! Is there any use case for super frequently updating raster tiles? Like satellite images are the slowest changing data in a map platform, aren't they?
If it is seriously needed for any use case, I'd recommend adding a tileXHR or tileCache or something similar to rasterSource and letting the developers choose it manually.
@hyperknot I feel like letting the developers choose would expose too much internal detail for a thing that should just work well automatically. So let's try to exhaust automatic heuristics first and resort to an explicit option if it doesn't work.
I was going to say we could probably just have tile requests always use Image directly, and use XHR only for sprites, but I wouldn't be surprised if there are use cases (e.g. weather apps) that depend on frequently updating raster tiles.
For browsers that support it, we could try out an XHR with req.responseType = 'blob' combined with createImageBitmap.
@jfirebaugh do you think it's worth the added complexity? As I see neither does Safari nor Edge supports it, while a simple Image.src is probably super optimised in every browser.
For browsers that support it, we could try out an XHR with req.responseType = 'blob' combined with createImageBitmap.
@jfirebaugh this likely won't help — looks like it's not the blob construction that's the bottleneck, but the XHR itself. Here's a screenshot from a stuttered frame (notice that all time is spent in send + open):
I wouldn't be surprised if there are use cases (e.g. weather apps) that depend on frequently updating raster tiles.
I think we could come up with a heuristic that supports this use case. E.g. if Cache-Control on the first XHR indicates that you can cache for >1hr, switch to simple image loads, otherwise continue with XHR. Thoughts?
P.S. #6995 and #6998 are PRs that remove two other bottlenecks that I identified when researching this issue.
I've merged all PRs (#6998 was already merged), and the image loading logic works perfectly, however the jankiness is still present (and can be up to 0.5 second).
OK, it seems to be depending on if the Developer Tools is open or not:
if Chrome developer tools is not open, the yank is I'd guess 1/10th of what it was previously, there really is a huge improvement here
if Chrome developer tools is open (even with disable caching turned off, even with "Stop recording network log") there is a jank, just like it was originally.
Unfortunately it's not possible to use the FPS meter without dev tools open, so it's a tricky case. But based on perception alone, the normal use case is about 10x better.
@hyperknot awesome! It's also worth noting that 128px tiles are an extreme case due to so many requests — performance after the patches is pretty smooth with bigger tile sizes.
I've ported the example to OpenLayers, with a similar animation (the easing is different).
In my opinion OL is super smooth even with developer tools open. FPS meter shows constant 60 FPS with one or two occasional frames at 30 FPS, or maybe 20 FPS.
I've looked into how OpenLayers handles raster tile loading, and I believe the reason why their equivalent is fast is that they use a TileQueue data structure that makes sure there are never more than 16 tiles loading in parallel or requested at once in one frame. This makes it avoid requesting short-lived tiles that e.g. get requested on zoom in near the borders of the map and then immediately go off the view when zooming further during an animation. This might be a possible solution to this feature request #5482, and we should definitely explore a similar approach.
Activity
mourner commentedon Jul 19, 2018
This seems to be some kind of regression with the source cache logic — most of the time is spend figuring out which tiles to show, not actual rendering or loading. Investigating now.
mourner commentedon Jul 19, 2018
Looks like it's not a regression, just an algorithm that dramatically slows down quadratically when the tile size goes down — it was only optimized for vector tiles, where you typically only see 6-7 tiles on the screen. Thinking about a faster one now...
mourner commentedon Jul 19, 2018
OK, I have a good lead on this. Will submit a PR tomorrow.
mourner commentedon Jul 20, 2018
Turns out that the jank on raster layers is currently dominated by XHR requests, which we use to load images since #1472 because of an issue with browsers not fully respecting
Cache-Control: no-cache(#1470). You can see how much snappier the raster test case becomes in 9b372d9, which uses the old image loading approach (git co bench-raster-tile-load,yarn run start-debug, then loadhttp://localhost:9966/debug/). If you switchgetImageback to XHR-based requests inajax.js, it becomes unusably janky, as reported.Since the original fix with XHR image loads was introduced specifically to fix sprite updates, and most image loads don't have short cache spans, I wonder if we can use some kind of a mixed approach. For example, a raster tile source would do its first request with XHR-based getImage, see if
cacheControlis small (no-cache, small enoughmax-ageor whatever), and then either continue using XHR or switch to simplenew Imagefor snappier performance. @jfirebaugh what do you think?hyperknot commentedon Jul 20, 2018
Thanks, it's great to see this! Is there any use case for super frequently updating raster tiles? Like satellite images are the slowest changing data in a map platform, aren't they?
If it is seriously needed for any use case, I'd recommend adding a tileXHR or tileCache or something similar to rasterSource and letting the developers choose it manually.
mourner commentedon Jul 20, 2018
@hyperknot I feel like letting the developers choose would expose too much internal detail for a thing that should just work well automatically. So let's try to exhaust automatic heuristics first and resort to an explicit option if it doesn't work.
jfirebaugh commentedon Jul 20, 2018
I was going to say we could probably just have tile requests always use
Imagedirectly, and use XHR only for sprites, but I wouldn't be surprised if there are use cases (e.g. weather apps) that depend on frequently updating raster tiles.For browsers that support it, we could try out an XHR with
req.responseType = 'blob'combined withcreateImageBitmap.hyperknot commentedon Jul 20, 2018
@jfirebaugh do you think it's worth the added complexity? As I see neither does Safari nor Edge supports it, while a simple Image.src is probably super optimised in every browser.
mourner commentedon Jul 20, 2018
@jfirebaugh this likely won't help — looks like it's not the blob construction that's the bottleneck, but the XHR itself. Here's a screenshot from a stuttered frame (notice that all time is spent in
send+open):I think we could come up with a heuristic that supports this use case. E.g. if
Cache-Controlon the first XHR indicates that you can cache for >1hr, switch to simple image loads, otherwise continue with XHR. Thoughts?P.S. #6995 and #6998 are PRs that remove two other bottlenecks that I identified when researching this issue.
use non-XHR raster tile loads when possible
use non-XHR raster tile loads when possible
use non-XHR raster tile loads when possible
mourner commentedon Jul 23, 2018
Added a proposal for addressing this issue in #7008.
@hyperknot try applying all three PRs (#7008, #6995, #6998) and let me know how the performance looks.
hyperknot commentedon Jul 23, 2018
I've merged all PRs (#6998 was already merged), and the image loading logic works perfectly, however the jankiness is still present (and can be up to 0.5 second).
Here is a codepen with an updated build:
https://codepen.io/hyperknot/full/vaxvJN/
hyperknot commentedon Jul 23, 2018
OK, it seems to be depending on if the Developer Tools is open or not:
Unfortunately it's not possible to use the FPS meter without dev tools open, so it's a tricky case. But based on perception alone, the normal use case is about 10x better.
mourner commentedon Jul 23, 2018
@hyperknot awesome! It's also worth noting that 128px tiles are an extreme case due to so many requests — performance after the patches is pretty smooth with bigger tile sizes.
hyperknot commentedon Jul 23, 2018
Yes, solving this case also helped the normal satellite tiles work super smoothly, thanks a lot for tackling it!
(I wouldn't consider this an extreme case, as there are only 4x tiles visible compared to Mapbox satellite (whose tile size is actually 256px)).
jfirebaugh commentedon Jul 23, 2018
For reference: https://bugs.chromium.org/p/chromium/issues/detail?id=348655.
use non-XHR raster tile loads when possible
use non-XHR raster tile loads when possible
mourner commentedon Jul 27, 2018
From #7008:
I've looked into how OpenLayers handles raster tile loading, and I believe the reason why their equivalent is fast is that they use a TileQueue data structure that makes sure there are never more than 16 tiles loading in parallel or requested at once in one frame. This makes it avoid requesting short-lived tiles that e.g. get requested on zoom in near the borders of the map and then immediately go off the view when zooming further during an animation. This might be a possible solution to this feature request #5482, and we should definitely explore a similar approach.
use non-XHR raster tile loads when possible
use non-XHR raster tile loads when possible
use non-XHR raster tile loads when possible
mourner commentedon Mar 1, 2019
This seems in a pretty good shape after #7497 and earlier improvements, so closing.