-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[core] Fast tileCount with help from @mapbox/sphericalmercator module #9906
Conversation
2fba28f to
65c1d27
Compare
| assert(maxZ < std::numeric_limits<uint8_t>::max()); | ||
|
|
||
| unsigned long result = 0;; | ||
| for (auto z = minZ; z <= maxZ; z++) { |
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.
auto → uint8_t
| } | ||
|
|
||
| unsigned long OfflineTilePyramidRegionDefinition::tileCount(SourceType type, uint16_t tileSize, const Range<uint8_t>& zoomRange) const { | ||
| double minZ = std::max<double>(util::coveringZoomLevel(minZoom, type, tileSize), zoomRange.min); |
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.
Can you refactor the code that's duplicated from tileCover into a function with the signature:
Range<uint8_t> coveringZoomRange(SourceType, uint16_t tileSize, const Range<uint8_t>& zoomRange) const|
|
||
| unsigned long result = 0;; | ||
| for (auto z = minZ; z <= maxZ; z++) { | ||
| auto count = util::tileCount(bounds, z, tileSize); |
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.
result += util::tileCount(bounds, z, tileSize)
| } | ||
|
|
||
| // Project lat, lon to point in a zoom-dependent world size | ||
| static Point<double> project(const LatLng& point, uint8_t zoom, uint16_t tileSize) { |
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.
Can this be written in terms of the existing project function, or vice versa?
8ddd56a to
0d732cb
Compare
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.
Use static_cast rather than C-style cast.
0d732cb to
9b19ab7
Compare
| std::vector<UnwrappedTileID> tileCover(const LatLngBounds&, int32_t z); | ||
|
|
||
| // Compute only the count of tiles needed for tileCover | ||
| unsigned long tileCount(const LatLngBounds&, uint8_t z, uint16_t tileSize); |
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.
Can we please use fixed width number types (like uint64_t)? Unfortunately, unsigned long is 32 bit on some and 64 bit on other platforms.
Closes #9675
Implement a separate
util::tileCount()method for computing the number of tiles that need to be downloaded for offline packs.The time for computing tile count for a bounding box around SF went from 12070 ms to 1 ms.
The failed attempts include:
tileCoveron the max zoom, and getting parents of those tiles up to min zoom. I was surprised by the cost ofboost::hash_combinewhich made this more expensive than runningtileCoverfor every zoom level.LatLngextents of the bounding box vsLatLngextents of a tile. This approached had way better performance but suffered from floating point errors due to the precision ofLatLngfor high zoom levels.Thanks to @jfirebaugh for pointing me to @mapbox/sphericalmercator