Use sparse entity-to-node mapping for ContactGraph#689
Merged
Conversation
Jondolf
commented
Apr 2, 2025
| nalgebra = { version = "0.33", features = ["convert-glam029"], optional = true } | ||
| serde = { version = "1", features = ["derive"], optional = true } | ||
| derive_more = "1" | ||
| arrayvec = "0.7" |
Member
Author
There was a problem hiding this comment.
Also noticed that this is unused in 3D
Member
Author
|
Using |
Member
Author
|
Or I'll actually merge this now and handle the |
This file contains hidden or 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
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.
Objective
The
ContactGraphmaintains an entity-to-node mapping using a customEntityDataIndex. This is similar to theCoarenain Rapier orSecondaryMapinslotmap.This works fine for physics entities. However, the structure's keys are the indices of the vector itself, which means that space is allocated for every entity from index 0 to the largest physics
Èntityindex. If you had a million non-physics entities, and one collider spawned later, it would also allocate space for those million non-physics entities.Solution
Replace
EntityDataIndexwith a similarSparseSecondaryEntityMap, backed by aHashMaprather than aVec. This is modeled after theSparseSecondaryMapinslotmap.This does most likely make random access slightly slower, but reduces memory usage.
Alternative:
ColliderIdWe could keep the current data structure, but maintain collider IDs that are separate from
EntityIDs.. This would let us only allocate for physics entities.However, we would then need to maintain an
Entity-to-ColliderIdmapping (or query forColliderId) at least to make the public API less painful. So, a sparse mapping is required regardless.We can explore this option later to see if it would be any faster, but for simplicity, I would prefer to keep using
Entitydirectly, and so only have the sparse mapping.