Throttling internal event listeners using requestAnimationFrame

Events like pointermove, wheel are not synced with requestAnimationFrame on browsers like Safari and Chrome with devtools open, see Browsers, input events, and frame throttling | Read the Tea Leaves. Is there interest in doing the throttling mentioned in that article for the internal Babylon.js event listeners? I’m willing to contribute.

Chrome:

Safari:

2 Likes

what would be the gain?

cc @amoebachant as it is his realm :slight_smile:

Stuff like scene picking uses pointermove, processing more than one of those events per frame is wasted effort.

2 Likes

makes total sense!

Thanks @fazil47 for asking this question! It does seem like an optimization worth considering, as long as it is efficient, since pointermove is a very hot codepath. If doing this slowed down that path on some browsers unnecessarily (which were already frame aligned), it may not be a large enough net positive. If you’d like to dig into this further, you could see how simple you could get the implementation, and try to measure the impact both to browsers that already align the events and those that don’t.

Thanks!

2 Likes