[scheduler] Expose message event handler and key #14226
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Scheduler uses a message event to schedule a callback that fires after paint. This happens on every frame until the queue is empty. An unfortunate consequence is that every other message event handler also gets called on every frame; even if they exit immediately, this adds up to significant per- frame overhead. Until there's a better way to insert work after paint, a workaround is to monkey-patch
addEventListenerso there's only a single listener that wraps all the other ones. When a messageevent is fired, we check if the event is Scheduler event. If it is, we call Scheduler, and skip the other event handlers entirely. (We could also use this same wrapper to defer the priority of the message event handlers, though that's a more drastic a change.)
This is a bit hacky, though, and probably doesn't belong in this package. It can be implemented in a wrapper, though, if we expose both the message key used by Scheduler message events and the Scheduler message listener.