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

Simplify and optimize some GraphNode find functions #5850

Merged
merged 4 commits into from
Dec 4, 2023

Conversation

NewboO
Copy link
Contributor

@NewboO NewboO commented Nov 25, 2023

Follow-up of #4603

This PR simplifies GraphNode.find and GraphNode.findOne.
It also avoids creating and merging lots of arrays in GraphNode.find which means less garbage.
In addition, GraphNode.findByName now simply calls GraphNode.findOne so the traversing logic isn't duplicated anymore.

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

@Maksims
Copy link
Contributor

Maksims commented Nov 25, 2023

Do you have a benchmarks with various hierarchy cases?

@mvaligursky mvaligursky added performance Relating to load times or frame rate area: graphics Graphics related issue labels Nov 27, 2023
src/scene/graph-node.js Show resolved Hide resolved
src/scene/graph-node.js Outdated Show resolved Hide resolved
@NewboO
Copy link
Contributor Author

NewboO commented Nov 27, 2023

Do you have a benchmarks with various hierarchy cases?

I ran somes on one of my projects which has a hierarchy of ~800 nodes.
Benchmarked from root and from a deeper node (only 80 descendants), finding by name both existing (100 occurrences to return from root, 5 from the deeper node) and non-existing:

GraphNode.find, existing name

                       |  old  |  new
--------------------------------------
800+ nodes (100k runs) |  5.3s |  2.5s
--------------------------------------
80 nodes (1M runs)     | 0.98s | 0.75s


GraphNode.find, non-existing name

                       |  old  |  new
--------------------------------------
800+ nodes (100k runs) |  4.6s |  2.5s
--------------------------------------
80 nodes (1M runs)     | 0.63s | 0.70s


GraphNode.findOne, existing name relatively deep

                       |   old  |   new
----------------------------------------
800+ nodes (100k runs) |  0.29s |  0.17s
----------------------------------------
80 nodes (1M runs)     | 0.027s | 0.036s


GraphNode.findOne, non-existing name

                       |  old  |  new
--------------------------------------
800+ nodes (100k runs) |  4.5s |  2.7s
--------------------------------------
80 nodes (1M runs)     | 0.56s | 0.69s

So it may be sometimes a bit slower when only a few nodes need to be checked, but it gets way faster on bigger hierarchies.

src/scene/graph-node.js Outdated Show resolved Hide resolved
@slimbuck
Copy link
Member

This PR seems to me a wonderful example of how simplifying code can make it more readable, maintainable and run faster all at the same time. Great job @NewboO !!

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.

Great work! I'm happy to merge this. @slimbuck ?

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.

LGTM! Thanks. 🙏

Co-authored-by: Will Eastcott <will@playcanvas.com>
@mvaligursky mvaligursky merged commit 218ce25 into playcanvas:main Dec 4, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: graphics Graphics related issue performance Relating to load times or frame rate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants