Bug: Performance Issue in updateHeights with High-Resolution Custom Terrain Providers

Summary

When using a high-resolution custom terrain provider (e.g., ArcGIS WorldElevation3D), updateHeights in QuadtreePrimitive struggles to keep up with entity height updates. The intersections with the terrain take significantly longer (often exceeding 50ms), while the time limit for updateHeights is only 2ms.

This results in a growing queue of tilesToUpdateHeights, leading to poor entity positioning and potential performance degradation. The issue does not occur when using Cesium.createWorldTerrainAsync().

Reproduction

Sandcastle example

Observations & Debugging

To analyze the issue, I added logging inside updateHeights as follows:

const currentTime = getTimestamp();
const deltaTime = currentTime - startTime; // Calculate elapsed time
if (currentTime >= endTime) {
    console.log(`Time slice exceeded: Δt = ${deltaTime} ms (limit: ${timeSlice} ms)`);
    console.log(`Queue size: tilesToUpdateHeights.length = ${tilesToUpdateHeights.length}`);
    console.log(`Last processed tile index: ${primitive._lastTileIndex}`);
    timeSliceMax = true;
    break;
}

After all tiles have been loaded, I keep seeing these logs:

Time slice exceeded: Δt = 53.59999990463257 ms (limit: 2 ms)
Queue size: tilesToUpdateHeights.length = 56
Last processed tile index: 1
Time slice exceeded: Δt = 86.2999997138977 ms (limit: 2 ms)
Queue size: tilesToUpdateHeights.length = 56
Last processed tile index: 1
...

Key Findings:

  • The intersection time consistently exceeds 50ms, whereas the function is only allowed 2ms per update cycle.
  • This causes tilesToUpdateHeights to grow indefinitely, preventing entity heights from updating.
  • Switching to Cesium.createWorldTerrainAsync() eliminates the issue, suggesting that high-resolution terrain data slows down intersections significantly.

Let me know if more logs or tests are needed!

I filed a bugreport here