Removing massive batch of labels and billboards, performance problem

I know that it is not possible to adding or removing batch of labels in primitive api for cesium. You need to one by one use add/remove method of collection. Collections have add method but don’t get array or something. However the documentation says:

" Calling add is expected constant time. However, the collection’s vertex buffer is rewritten; this operations is O(n) and also incurs CPU to GPU overhead. For best performance, add as many billboards as possible before calling update ."
or
" Calling remove is expected constant time. However, the collection’s vertex buffer is rewritten - an O(n) operation that also incurs CPU to GPU overhead. For best performance, remove as many labels as possible before calling update"

How to use update method at once? Afaik, the render loop controls the preparing objects to send the gpu. Wouldn’t be better if add and remove methods could get also primitive arrays or there could be addMultiple, removeMultiple methods created?

When you try to remove 70k labels and 45k billboards, that blocks the main thread and takes so much time. The documentation also suggest that it is less time consuming just to hide and show primitives. So, if I hide all the objects in the map and achieve removing operation asyncronously in future time by small batches, then the time for newly added primitives increase since there are 100k primitives on the map already waiting to be removed.

To sum it up my question is how to remove massive batch of labels and billboards from cesium then execute update operation at once? The documentation is not clear about how to achieve this. Note that there could be some other label and billboard primitives already existed and removeAll method is not an option because of that.

Hello there,

When you try to remove 70k labels and 45k billboards,

Could you elaborate on your use case a bit? I’d like to understand why its needed to remove so many at once.

Overall the best thing to do would be to avoiding adding and removing primitives as much as possible. Instead (as you mentioned) hiding the primitives and then re-purposing them for new labels. It sounds like you are removing some billboards and labels and adding other back later. It would be best to reserve primitives in a pool and re-use them.

One thing to consider with that many labels is if they are all needed on screen at one time. It’s bad for performance, but users might have a difficult time parsing all those labels. Clustering will group labels together until zoomed in. It’s available in the entity API, but you could consider an implementation to the same effect for Primitive labels, which would require far fewer being rendered at one time.

Thanks,
Gabby