Skip to content
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

Globe: symbol and coveringTiles optimizations #4778

Merged
merged 13 commits into from
Oct 15, 2024

Conversation

kubapelc
Copy link
Collaborator

@kubapelc kubapelc commented Sep 30, 2024

This PR ports symbol rendering optimizations from non-globe main branch to current globe-based main and adds some other globe-specific optimizations on top:

  • Added a fast path for symbol projection for mercator projection, comparable to MapLibre 4.7 in performance - this just fixes a performance regression that was present in the globe branch.
  • Improved collision box placement performance by not calling isTilePositionOccluded (the information was already computed beforehand).
  • Improved globe's coveringTiles performance by caching tile AABBs instead of recomputing them every time.
  • Fixed globe's coveringTiles incorrectly returning hundreds of hidden tiles as visible if the camera is sufficiently pitched.
  • Improved globe's coveringTiles tile visibility accuracy, reducing the number of returned tiles and thus improving performance.
  • Added a SymbolCollisionBoxGlobe benchmark for symbol placement under globe projection. This is the same as SymbolCollisionBox, just with globe projection used instead of mercator.
  • Fixes bad line scaling near the poles
  • Fixed globe loading tiles at unnecessarily high zoom level when pitched

Below are benchmark results for mercator projection. Here "main" essentially represents globe branch without optimizations ported over, thus it is relatively slow.

mercator symbol placement benchmark

These next two figures are the new globe placement benchmark, first on the current main branch, then on this PR branch.

globe placement on current main

globe placement on this PR branch

@codecov-commenter
Copy link

codecov-commenter commented Sep 30, 2024

Codecov Report

Attention: Patch coverage is 88.02395% with 20 lines in your changes missing coverage. Please review.

Project coverage is 88.08%. Comparing base (835abdb) to head (a6a7f3d).
Report is 16 commits behind head on main.

Files with missing lines Patch % Lines
src/geo/projection/globe_transform.ts 50.00% 6 Missing and 12 partials ⚠️
src/geo/projection/mercator_transform.ts 93.75% 0 Missing and 1 partial ⚠️
src/symbol/collision_index.ts 98.79% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4778      +/-   ##
==========================================
+ Coverage   87.99%   88.08%   +0.09%     
==========================================
  Files         265      265              
  Lines       37591    37659      +68     
  Branches     2337     2343       +6     
==========================================
+ Hits        33078    33172      +94     
+ Misses       3482     3456      -26     
  Partials     1031     1031              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@HarelM
Copy link
Collaborator

HarelM commented Sep 30, 2024

I've added a few comments. thanks for this!
There is a PR that also looks at covering tiles here, it would be great to get your input there:

(it's currently closed due to globe branch deletion, it should be opened soon).

@HarelM
Copy link
Collaborator

HarelM commented Oct 2, 2024

New PR is here:

@NathanMOlson - can you check that the covering tiles optimization and improvements done here are incorporated in your PR - I would like to separate responsibilities: have Nathan's PR address covering tiles stuff and have this PR focus on symbol optimizations.

@kubapelc
Copy link
Collaborator Author

kubapelc commented Oct 2, 2024

@HarelM @NathanMOlson thank you for your feedback! I will address it and improve this PR in a week or two, sadly I need to focus on other things in the meantime. I think this PR will not create merge conflicts with the terrain tile LOD PR, since that changes different parts of the covering tiles logic.

@NathanMOlson
Copy link
Contributor

can you check that the covering tiles optimization and improvements done here are incorporated in your PR

The two optimizations for covering tiles in this PR are

  1. Caching of tile AABBs. This needs changes to address unbounded memory growth.
  2. Early return if tileBelowHorizon(). I'm not convinced this is actually an improvement.

I don't think these changes are ready to be incorporated in my PR.

@HarelM
Copy link
Collaborator

HarelM commented Oct 2, 2024

I would advise to remove covering tiles related logic from this PR and optionally add it to @NathanMOlson's PR if applicable.

@HarelM HarelM mentioned this pull request Oct 9, 2024
15 tasks
@kubapelc
Copy link
Collaborator Author

I have reverted most of coveringTiles changes, with one exception at line 84:

return Math.min(centerDist, cameraDist) * 2 <= radiusOfMaxLvlLodInTiles * tileSize; // Multiply distance by 2, because the subdivided tiles would be half the size

This is a simple bugfix, before this change globe displayed unnecessarily many tiles at high zoom levels. This alone improves performance a lot when camera is pitched.

I will try to implement a better tile culling by using general bounding frustums instead of AABBs. Frustums can approximate the actual tile shape much more tightly, thus leading to more discarded tiles, thus improving performance. A frustum-frustum visibility test should not be much slower than frustum-AABB test, but I will measure the times and create a benchmark. I will also implement a tile bounding volume cache that does not leak memory. I will do that as a separate PR.

@HarelM
Copy link
Collaborator

HarelM commented Oct 15, 2024

Added a few more comments. Otherwise looks good enough to be merged. Thanks!

@HarelM
Copy link
Collaborator

HarelM commented Oct 15, 2024

Can you update the branch from main to resolve conflicts?
I believe other comments were addressed.

@kubapelc
Copy link
Collaborator Author

Should be fixed now, I also fixed the changelog wording and the failing render test (reverted the expected image to its state before this PR).

@HarelM HarelM merged commit 51bd024 into maplibre:main Oct 15, 2024
15 checks passed
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.

4 participants