-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Merged
mvaligursky
merged 4 commits into
playcanvas:main_v1
from
Maksims:button-component-remove-entity-reference
Jan 6, 2025
Merged
ButtonComponent remove EntityReference & optimize add/remove speed. #7204
mvaligursky
merged 4 commits into
playcanvas:main_v1
from
Maksims:button-component-remove-entity-reference
Jan 6, 2025
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Maksims
changed the title
ButtonComponent remove EntityReference
ButtonComponent remove EntityReference & optimize add/remove speed.
Dec 16, 2024
mvaligursky
added
performance
Relating to load times or frame rate
area: ui
UI related issue
labels
Jan 6, 2025
mvaligursky
reviewed
Jan 6, 2025
|
||
if (this._imageReference.hasComponent('element')) { | ||
this._isApplyingSprite = true; | ||
spriteFrame = spriteFrame || 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be just a default value for the parameter?
_applySprite(spriteAsset, spriteFrame = 0) {
mvaligursky
approved these changes
Jan 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
mvaligursky
pushed a commit
that referenced
this pull request
Jan 6, 2025
…7204) * ButtonComponent remove EntityReference * remove reliance on component system global event lists * lint # Conflicts: # src/framework/components/button/component.js
cherry picked to main_v2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.