perf(terrain): avoid allocating tile IDs and matrices that are then discarded - #8173
perf(terrain): avoid allocating tile IDs and matrices that are then discarded#8173Alchez wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8173 +/- ##
=======================================
Coverage 93.91% 93.92%
=======================================
Files 290 290
Lines 24915 24916 +1
Branches 6575 6575
=======================================
+ Hits 23399 23402 +3
+ Misses 1516 1514 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
This doesn't sound like a big perf gain. can you share the bench results? |
|
@HarelM sorry I forgot to post the bench results. I'll add it to the description.
By itself, I agree that it's not a significant improvement. But I'd argue for two things:
maplibre-gl-js/src/tile/terrain_tile_manager.ts Lines 230 to 243 in 6b191d5 |
|
Since this has the risk of creating issue in the future I don't see this as a real perf improvement worth pursuing. I prefer to focus on things that will make the terrain work faster on mobile devices, which is where it currently suffers... |
|
@HarelM okay, that's fair. I'll close this one. I do have another separate terrain improvement that may be more applicable for mobile performance. I'll raise it shortly. |
When using terrain, the tile manager is allocating a tile ID and a 16-element matrix for every renderable terrain tile, but most of it is wasted compute that adds up.
flowchart TD subgraph after["After — decide, then allocate"] A1[next terrain tile] --> A2{same, child<br/>or parent?} A2 -->|no| A3[continue<br/>nothing allocated] A2 -->|yes| A4[clone tile ID<br/>copy scratch matrix] A3 --> A1 A4 --> A1 end subgraph before["Before — allocate, then decide"] B1[next terrain tile] --> B2[clone tile ID<br/>allocate Float64Array 16] B2 --> B3{same, child<br/>or parent?} B3 -->|no| B4[continue<br/>both discarded] B3 -->|yes| B5[keep] B4 --> B1 B5 --> B1 endAfter applying the fix, every frame should save about 0.15-1.05ms of compute (which is about 1-7% of a 60FPS budget).
Bench results:
The factors seem big, but they're only in-function improvements, and this function isn't called very many times for a frame, so effective improvement is still only the range noted above.
Related to:
Launch Checklist
*.bench.ts), post before/after results ofnpm run bench(the compare workflow is intest/bench/README.md).CHANGELOG.mdunder the## mainsection.Assisted-By: Claude Opus 5