Skip to content

Conversation

SOF3
Copy link
Contributor

@SOF3 SOF3 commented Oct 12, 2025

Objective

  • Describe the objective or issue this PR addresses.
  • If you're fixing a specific issue, say "Fixes #X".

Add a more memory-efficient relationship source collection data structure for relationships with up to one child most of the time.

Solution

  • Describe the solution used to achieve the objective above.

Introduces a new optional dependency wordvec, under the feature wordvec, such that

WordVec<Entity, 1>

can be used to substitute

SmallVec<[Entity; 1]>

where the former only takes 16 bytes instead of 24 bytes with comparable performance to SmallVec, particularly 20%-40% when used as Vec<WordVec<Entity, 1>> to index other entities, but 40% slower during single-item pushing.

Accessing Vec<X<usize>> for X = Vec/ThinVec/SmallVec/WordVec (with N = 1) where vec.len() == 1000 && vec[i].len() == 1 for i in 0 to 1000 (effectively Query<&Children>.iter().flatten().for_each(|e| *u64_query.get_mut(e).unwrap() += 1)):
image

Pushing 1, 2, 3 in order to X<u16> with N = 3:
image

Testing

  • Did you test these changes? If so, how?
  • Are there any parts that need more testing?
  • How can other people (reviewers) test your changes? Is there anything specific they need to know?
  • If relevant, what platforms did you test these changes on, and are there any important ones you can't test?

The tests for SmallVec implementation in relationship_source_collection.rs are duplicated for WordVec as-is.

@SOF3
Copy link
Contributor Author

SOF3 commented Oct 12, 2025

Not very familiar with the bevy CI system, not sure if any changes are required to enable the wordvec feature in the CI by default.

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times X-Controversial There is active debate or serious implications around merging this PR S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 13, 2025
@alice-i-cecile
Copy link
Member

I'm generally a bit skeptical about pulling in more dependencies for stuff like this, but the implementation is fine. Very annoying that orphan rule makes us decide on this upstream.

@SOF3
Copy link
Contributor Author

SOF3 commented Oct 14, 2025

It is also possible to implement this in the wordvec crate as well, but my intuition is that wordvec is supposd to be lower-level than bevy.

@alice-i-cecile
Copy link
Member

It is also possible to implement this in the wordvec crate as well, but my intuition is that wordvec is supposd to be lower-level than bevy.

Agreed, bevy is a better home for this than wordvec.

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

Labels

A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Controversial There is active debate or serious implications around merging this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants