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

Avoid List<T> O(n) operations #18

Open
Genbox opened this issue Apr 12, 2017 · 2 comments
Open

Avoid List<T> O(n) operations #18

Genbox opened this issue Apr 12, 2017 · 2 comments

Comments

@Genbox
Copy link
Owner

Genbox commented Apr 12, 2017

To simplify the code, Velcro Physics uses simple lists instead of the linked lists Box2D uses. However, operations such as Contains() and Remove() on List are O(n) operations, which slows down the engine considerably when working with many fixtures on a body.

@Genbox
Copy link
Owner Author

Genbox commented Jun 4, 2017

I've created a generic doubly linked list that is circular to avoid branches in code. The enumerator simply iterates the list using the count to void infinite circulation.

It is 2x as slow when iterating, but much faster when removing nodes.
We allocate 2x the memory for the linked list as well since it needs a container to hold the references.

image

@Genbox
Copy link
Owner Author

Genbox commented Jun 4, 2017

Note that I tested with a version that is non-generic and got identical results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant