Skip to content

Conversation

@Aries1542
Copy link
Contributor

The name of Two.Group.getById() somewhat implies it would use the Two.Group.children.ids map but actually just loops through every child until found, which can decrease performance if you need to grab many objects from a large group by id and are unaware.

The optimization checks if the object is present in the ids map before looping through all children, and returns the item if found. It still reverts to the old way of checking if the object isn't found in the ids map, so nested objects and objects not in the id map will still be found.

Validated the speed increase with the test cases here: https://github.com/Aries1542/two.js-speed-test.
For those cases, Two.Group.getById() went from around 30x as slow to about equal to Two.Group.children.ids[] for random cases and 60x as slow to about equal in the worst case.

I wasn't able to get your tests running on my machine however so that should probably still be checked.

@jonobr1 jonobr1 merged commit 6ca8ef9 into jonobr1:dev Apr 3, 2025
1 check passed
@jonobr1
Copy link
Owner

jonobr1 commented Apr 3, 2025

Awesome, thank you!

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.

2 participants