Performance bug with DynamicEllipsoidGeometryUpdater with constant color
- Dominant language
- JavaScript
- Stars
- 15.7k
- Forks
- 3.9k
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 34
Description
Hi have an entity with both a billboard and an ellipsoid, defined as
```
const entity = viewer.entities.add({
// Use our computed positions
position: posProp,
billboard: ...,
ellipsoid: {
...
material: Cesium.Color.fromCssColorString(
color
) ...
},
path: undefined
});
```
I noticed that every frame, the shaders for the ellipsoid would be recomputed. Stepping through I noticed that this piece of code in `Primitive.prototype.update` would always be triggered:
```
if (this._material !== material ) {
this._material = material;
createSP = true;
}
```
I then noticed that this line in `DynamicEllipsoidGeometryUpdater` would always create a new material:
```
var material = MaterialProperty.getValue(time, defaultValue(ellipsoid.material, defaultMaterial), this._material);
```
Recreating the shaders every frame, even though nothing changes seems to have a significant performance impact. I've applied the following workaround as a quick fix in `DynamicEllipsoidGeometryUpdater`, but I'm not sure this breaks other scenarios / whether this fix is made at the right level. It solves my immediate problem though:
```
var material = MaterialProperty.getValue(time, defaultValue(ellipsoid.material, defaultMaterial), this._material);
this._material = material; // added line to fix perf bug
```
(Cesium 1.46.1)
Contributor guide
Research direction
Reproduce the issue with an entity containing both a billboard and an ellipsoid with a constant color. Trace DynamicEllipsoidGeometryUpdater's MaterialProperty.getValue call into Primitive.prototype.update, focusing on why the material identity changes each frame. Done means unchanged constant materials no longer trigger shader recomputation during updates.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, performance
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100