Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventHandle.off - performance improvements #7137

Merged
merged 1 commit into from
Nov 29, 2024

Conversation

Maksims
Copy link
Collaborator

@Maksims Maksims commented Nov 25, 2024

No logic changes.

Since EventHandle was implemented, developer lives for events management have been simplified. At the same time there is a new opportunity for optimization. This PR does just that, when using EventHandle.off, instead of scanning callbacks and comparing name, callback and scope, now it uses EventHandle itself and checks if it is in array, if so, removes it.

This leads to massive performance improvements when .off is called on EventHandle vs .off on EventHandler.

One of these cases is onDisable on RenderComponent (and similar components). On large scenes with a lot of render components scene._callbacks['set:layers'] - becomes a very large array, the same applies to app.layers._callbacks.

In some of our projects, disabling render components leads to a massive lag spike, in one specific project disabling big chunk of a scene takes ~3500ms, with this optimization time is reduces to ~900ms.

To benefit from this optimization, we need to use EventHandle within engine as much as possible, instead of a off on EventHandler's.

PR's with EventHandle.off in critical places coming after this one.

I confirm I have read the contributing guidelines and signed the Contributor License Agreement.

Copy link
Contributor

@willeastcott willeastcott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to merge @mvaligursky?

Copy link
Contributor

@mvaligursky mvaligursky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep this looks fantastic.

@mvaligursky mvaligursky merged commit 54136e5 into playcanvas:main_v1 Nov 29, 2024
8 checks passed
@mvaligursky
Copy link
Contributor

also cherry-picked to v2

@Maksims Maksims deleted the event-handler-off-perf branch December 16, 2024 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Relating to load times or frame rate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants