-
-
Notifications
You must be signed in to change notification settings - Fork 861
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
perf!: reduce work to build and fix bugs in TileLayer
, and improve culling of off-screen tiles
#1718
Conversation
c5e4d2b
to
f317b41
Compare
Just to note with the latest commit and culling tiles off screen (I thought we already did this!):
|
Maybe you did something else? I did check the filter I added (where(visibleTileRange.contains)) and it does filter out tiles. It's not a no-op.
It shouldn't. I'm not pruning any more aggressively. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears this has broken the zooming pruning/replacement logic (this fork on the left, latest 'master' on the right):
2023-11-05.11-04-10.mp4
Great catch with the zooming. It was the render-pruning (not storage pruning). I now took the cheap way out. I checked again, there's still render-pruning happening but there's plenty of optimization left on the table. The problem was that when zooming in the center of the parent tile wasn't within visible bounds anymore. To be correct we'd have to check for overlapping bounding boxes instead. |
Just to roughly quanitfy the impact. I've seen roughly a 4x reduction in time spend per frame on "building" the tile-layer. For rendering only a map, overall I've seen a 30+% reduction on the ui thread. |
TileLayer
TileLayer
TileLayer
& improve culling of off-screen tiles
… do not render tiles off screen. Unlike the first two, the latter also reduces load on the render thread.
…oom levels either when all tiles at target level are available or if they would be off-screen.
I clawed back some the render thread performance improvements left on the table, i.e. the render pruning is more aggressive again. It's not perfect, we could be more selective (like the storage pruning) when the tiles at the target zoom-level are not yet ready. I'm also reaching a point where my UI thread has plenty of head-room and the vast majority of frame drops are constituted by the render thread. At this point any render savings, even at the expense of some more work on the UI thread, are worth their weight in gold. |
…g to render the absolute minimum number of tiles that maximizes coverage. As a opportunistic cleanup, also use Bounds<double> specifically wherever we deal with pixels.
I couldn't resist. Now we're rendering the actual minimal number of tiles w/o visual regressions. No more render performance left on the table by the tile renderer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @ignatz, thanks for the pull request. I haven't tested the changes yet but I like the optimisation tweaks. (:
Can you check my comments?
doing a bit of profiling on my end. with the PR and comparing it to master. doing a simple pinch and zoom in and out im getting an average raster time of 4.7ms, and UI time of 1.7 ms. on master im getting 4.0ms raster, and 2.3ms UI. This is with rendering 3 raster layers on an unfolded z fold 5. im not really sure where the increase in raster time is coming from. There is a reduction in UI time but im not sure if that makes sense to trade off with raster time (given that is going to be our limiting factor for any vector layers. I haven't taken a detailed look at the code yet though. |
@mootw yeah, I also didn't see a significant change in raster times either on Android either. W/o any reliable statistics, I've seen it go either way. We're definitely rendering fewer tiles though. As for the explanation why this doesn't show clear savings, I can only offer hypotheses:
FWIW, the canvaskit renderer I'm actually seeing a slight improvement 🤷 As for my argument weighing off ui-thread vs raster-thread time, you might have miss-understood my babbling. I can leave the rastering untouched and do even less on the UI thread. I deliberately, did more work on the ui threadto reduce the number of tiles being put on screen. However, as you noticed yourself, it doesn't seem to pay off on Android in a clear way. Might be interesting to look at iOS 🤷 EDIT: one more thing to keep in mind when playing around: if you're just pinching in and out across one zoom-boundary you may also trigger some caching effects, e.g. some raster cached images getting invalidated slightly sooner when taken off screen already before storage pruning. |
I had some issues with displaying the correct tiles. This only happens if the tiles are loading from the web and not in memory cached. Aufzeichnung.2023-11-07.222307.mp4Performed tests:When zooming out:
When zooming in:
This behaviour can be even better reproduced by using the ZoomButtonsPlugins page of the example app.
|
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Great catch and hanks for the detailed explanation, that made it crystal clear. From the video is hard to judge when the follow-up input was given. Should be fixed now. For context, the z-index sorting is broken at head. Funny enough it has two bugs that almost cancel each other out:
As a result, we render them in insertion order, with later tiles rendered on top due to the default hash map implementation preserving insertion order. When I changed the map representation to a map that does not preserve insertion order, we started to stack them in random order and the broken sorting started to surface more prominently 🤣 |
TileLayer
& improve culling of off-screen tilesTileLayer
& improve culling of off-screen tiles
Thats somehow kind of impressive. You can decide how to resolve the last change request. After that it's ready to merge. |
I snuck in one more minor change. I merged Thanks for the review. Great catch on the tile stacking order. |
TileLayer
& improve culling of off-screen tilesTileLayer
, and improve culling of off-screen tiles
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Ok, I'll review this tomorrow as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @ignatz!
TileLayer
, and improve culling of off-screen tilesTileLayer
, and improve culling of off-screen tiles
Thanks for the review.
🤣 great example of process getting in the way :hide: |
A couple of performance improvements: