The UI rendering delayed when remove and add actions are constantly applied

viewer.scene.primitives.remove(primitive);
primitive = viewer.scene.primitives.add(
new Cesium.Primitive({
geometryInstances: new Cesium.GeometryInstance({
geometry: new Cesium.PolylineGeometry({
positions: Cesium.Cartesian3.fromDegreesArrayHeights(arrs),
width: 2,
}),
}),
appearance: new Cesium.PolylineMaterialAppearance({
material: Cesium.Material.fromType(Cesium.Material.PolylineDashType, {
color: Cesium.Color.WHITE, // 线条颜色
}),
}),
})
);

the code above is in a mousemove event to draw a dynamic polyline,but it is delayed and when mouse moved quickly the primitive even disappeared! what should i do? I just want to make a tool to draw a dynamic polyline

Hi @funny, thanks for the question.

Our Clipping Regions sandcastle shows a demonstration of drawing out polygons and using them as new clipping regions. Maybe parts of that code can help you achieve what you want?

Otherwise would you be able to provide a minimal sandcastle example that demonstrates the issue? An initial guess is that your code is getting slowed down by recreating the primitive every time you move the mouse instead of just updating one primitive which is using up excess memory.