Multiple onBeforeRenderObservables performance faq

Will there be any performance loss when adding multiple onBeforeRenderObservables to the scene? Does this performance need to be considered? If so, I will try to write the processing logic in the same onBeforeRenderObservable.
If this kind of loss is not ignored, then I can use it with confidence and boldness.

Here is the Observer class:

Each Observer as an object adds some tiny load to the render loop. So, if you don’t need to remove some of your observers, probably the best solution is to use Observer masks.
A given Observable can notify its observer using a particular mask value, only the Observers registered with this mask value will be notified.

  • This enable a more fine grained execution without having to rely on multiple different Observable objects.
  • For instance you may have a given Observable that have four different types of notifications: Move (mask = 0x01), Stop (mask = 0x02), Turn Right (mask = 0X04), Turn Left (mask = 0X08).
  • A given observer can register itself with only Move and Stop (mask = 0x03), then it will only be notified when one of these two occurs and will never be for Turn Left/Right.
    Some more info here (API) - Observable | Babylon.js Documentation
    Docs - Observables | Babylon.js Documentation
2 Likes

I think it is all a scaling issue.

A handful will be totally ok but from 1000+ I would try to think to something else.

As with any perf related concerns, knowing any situation is usually different, the simplest is to measure it on your use case.

2 Likes