Infinite scroll 2D is really slow with polygons
- Open the viewer
- Drag drop the attached GeoJSON file
- Switch to 2D mode
The map is lags pretty badly in 2D infinite scroll mode. The performance is fine in 3D and is much better if you use the rotatable 2D map instead
@bagnell a number of users on the forum have been complaining about slow polygons when upgrading from 1.2x to 1.30+. Do you know of anything that changed that might have caused that?
@hpinkos do you have links to the forum issues?
@bagnell sounds like something is being computed per-vertex/triangle per-frame. Perhaps it is missing a coarse-grained check?
Forum posts:
https://groups.google.com/d/msg/cesium-dev/hXC8gxdi3uE/ZBWHUL6jAgAJ https://groups.google.com/d/msg/cesium-dev/wT2jkCrvvGQ/WdrP3QgmAwAJ
Also reported by @forest21000 in #7694
Reported again by @zhangchn in https://github.com/CesiumGS/cesium/issues/10304.
Reported again by @zhangchn in #10304.
The performance issue in SCENE2D could NOT be alleviated by using MapMode2D.ROTATE.
I am also seeing this same issue, even with MapMode2D.ROTATE enabled. Lower frame rate and higher CPU usage when 2D is compared to 3D.
Hey folks. Running into a similar issue here. I'll preface this by saying I believe this only affects issues with MapMode2D.INFINITE_SCROLL -- issues that affect both INFINITE_SCROLL and ROTATE might be a separate, unrelated issue.
I did a little debugging, and the following diff to execute2DViewportCommands seems to fix it my performance issues...
diff --git a/packages/engine/Source/Scene/Scene.js b/packages/engine/Source/Scene/Scene.js
index e438fdf87e..e52b0d2723 100644
--- a/packages/engine/Source/Scene/Scene.js
+++ b/packages/engine/Source/Scene/Scene.js
@@ -3310,8 +3310,10 @@ function execute2DViewportCommands(scene, passState) {
}
camera._setTransform(transform);
- Cartesian3.clone(position, camera.position);
+ camera.position.x = position.x;
+ camera.position.y = position.y;
+ // camera.position.z = position.z;
camera.frustum = frustum.clone();
passState.viewport = originalViewport;
}
Setting camera.position.z seems to make the issue come back. Digging a little deeper, it looks like the camera's z is getting set in executeCommands to avoid z-fighting.
https://github.com/CesiumGS/cesium/blob/47b5d295facaca795381bf607b78cc60c643fd85/packages/engine/Source/Scene/Scene.js#L2614-L2617
So this change performed in executeCommands was getting reverted when resetting the camera's position in execute2DViewportCommands. If this seems like a reasonable change, I'm happy to open a PR 😄
cc @ggetz
This change also appears to fix https://github.com/CesiumGS/cesium/issues/8302 (polyline zIndex issues in INFINITE_SCROLL mode)!
2 more examples of slow 2D performance for polylines and markers/cluster shared in this forums thread https://community.cesium.com/t/performance-tanks-in-2d-view-but-is-fine-in-3d/42439/3