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 covering tiles optimization #4937

Merged
merged 16 commits into from
Nov 6, 2024

Conversation

kubapelc
Copy link
Collaborator

Improves the performance of globe's coveringTiles function, adds benchmarks to measure globe coveringTiles performance, also likely slightly improves mercator's coveringTiles performance (not measured, but some of the changes should help there too).

Improvements:

  • Adds a cache for tile AABBs to avoid recomputing them every time. The cache is cleared at the beginning of every frame, only keeping the tile AABBs that were accessed in the last frame. Any two consecutive frames should mostly be viewing the same set of tiles, so most of the cache should be reused. (Only the AABB cache idea from Globe: symbol and coveringTiles optimizations #4778 is implemented, not the accurate tile-frustum intersections.)
  • Improves performance of plane-AABB intersection test
  • Improves frustum-AABB performance by applying the pervious optimization to the frustum's 6 planes
  • Simplifies the final test in frustum-AABB intersection by precomputing the frustum's bounding box

Performance

There are two benchmarks, one with the camera looking at the globe from above, one with a pitched camera. The camera slowly pans to the east during the benchmark. Here are the rough contributions of individual changes:

Change Unpitched Pitched
Baseline 13.5 ms 21.0 ms
Cached AABBs 9.7 ms 14.0 ms
+FastAABBplane 8.8 ms 12.2 ms
+FastFrustum 7.4 ms 9.8 ms
+FrustumBounds 7.4 ms 9.5 ms

@codecov-commenter
Copy link

codecov-commenter commented Oct 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.08%. Comparing base (c8a5ea8) to head (35fe7fc).
Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4937      +/-   ##
==========================================
- Coverage   89.13%   89.08%   -0.06%     
==========================================
  Files         267      269       +2     
  Lines       38234    38268      +34     
  Branches     2347     2356       +9     
==========================================
+ Hits        34081    34090       +9     
- Misses       3151     3174      +23     
- Partials     1002     1004       +2     

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

@HarelM
Copy link
Collaborator

HarelM commented Oct 30, 2024

The following PR is nearing its merge:

If you need, I can create a branch in this repo for collaboration, so you could open this PR against the updates made in the above PR, but otherwise, I prefer to have the above PR merged first to avoid conflicts on the hard work @NathanMOlson did.

@kubapelc
Copy link
Collaborator Author

Lets wait for #4779 to be merged first.

@birkskyum birkskyum added the globe Globe related issues label Nov 1, 2024
@birkskyum
Copy link
Member

@kubapelc , does this affect tile loading of the globe when the terrain3d is active too?

@kubapelc
Copy link
Collaborator Author

kubapelc commented Nov 4, 2024

does this affect tile loading of the globe when the terrain3d is active too?

It should not, this PR does not change functionality of tile culling, just makes it faster.

But globe coveringTiles so far assumes that there is no terrain and does not take tile min/max elevation into account when generating AABBs. I think it should not be an issue for the purposes of porting terrain to globe.

I'd like to redo globe coveringTiles to not use AABBs, since they do not approximate tiles on a sphere very well, and use oriented bounding boxes instead. I would add support for tile min/max elevation along with this.

@birkskyum
Copy link
Member

birkskyum commented Nov 4, 2024

@kubapelc , sounds great - note the terrain is actually fully working at this point on globe, except for an issue with the mesh near the poles #4984

@HarelM
Copy link
Collaborator

HarelM commented Nov 4, 2024

Converting tiles have been merged, this can now proceed.

# Conflicts:
#	src/geo/projection/globe_covering_tiles.test.ts
#	src/geo/projection/globe_covering_tiles.ts
#	src/geo/projection/globe_transform.ts
@HarelM
Copy link
Collaborator

HarelM commented Nov 4, 2024

Can you add some tests and a changelog entry?

@birkskyum birkskyum added this to the 5.0 milestone Nov 5, 2024
@kubapelc
Copy link
Collaborator Author

kubapelc commented Nov 6, 2024

Can you add some tests and a changelog entry?

I've added both. Most of the changes were already covered by existing tests, I've added tests for aabb-plane intersection and for the aabb cache.

src/util/primitives.ts Outdated Show resolved Hide resolved
src/util/primitives.ts Outdated Show resolved Hide resolved
@HarelM
Copy link
Collaborator

HarelM commented Nov 6, 2024

This looks straight forward and good, thanks!
Added a few minor comments.

@HarelM HarelM merged commit 138ed60 into maplibre:main Nov 6, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
globe Globe related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants