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

ButtonComponent remove EntityReference & optimize add/remove speed. #7204

Open
wants to merge 2 commits into
base: main_v1
Choose a base branch
from

Conversation

Maksims
Copy link
Collaborator

@Maksims Maksims commented Dec 16, 2024

Related to #7195

This PR does not change any APIs.

This PR removes the dependency on EntityReference by ButtonComponent. Instead, it manages its own events by subscribing and unsubscribing to imageEntity's ElementComponent's life and its relevant properties.
Also, it removes reliance on ComponentSystem's global event lists (described here: #7202), to ensure it does not get slower exponentially with the number of Button and Element Components in the scene.

Due to improvements for global event lists on ElementComponentSystem, Element and similar UI components also benefit from this PR. Similar PR for them will come later to keep each PR manageable and narrow.

We had a few projects, which are very UI heavy, with inventory buttons, a lot of UI elements, dynamically created icons all over and so on. We've noticed that the time it takes to modify hierarchy in runtime grows significantly as the project scales in size. This PR addresses some of that.

Here are some tests:

Create a number of entities with button and element components and then remove them.

Current engine:

Quantity: 777
Add: ~145ms (avg. per 1k: ~187ms)
Remove: ~87ms (avg. per 1k: ~112ms)
Average time per 1,000:

Quantity: 2840
Add: ~877ms (avg. per 1k: ~309ms)
Remove: ~839ms (avg. per 1k: ~295ms)

With this PR:

Quantity: 777
Add: ~114ms (avg. per 1k: ~147ms)
Remove: ~25ms (avg. per 1k: ~32ms)

Quantity: 2840
Add: ~286ms (avg. per 1k: ~101ms)
Remove: ~93ms (avg. per 1k: ~33ms)

Results:

From the tests, you can see that the cost of creating an Entity with Button and Element components grows exponentially (3rd test shows) with a number of similar Entities already in the scene.
And with this PR this is not the case, and the cost is constant.

The speed benefits are (it goes higher the more similar entities are in the scene):

Creation speed ~21%-67%+ improvement.
Deletion speed ~71%-89%+ improvement.

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

@Maksims Maksims changed the title ButtonComponent remove EntityReference ButtonComponent remove EntityReference & optimize add/remove speed. Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant