Skip to content

Remove insert_or_spawn function family #18148

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

ElliottjPierce
Copy link
Contributor

@ElliottjPierce ElliottjPierce commented Mar 3, 2025

Objective

Based on and closes #18054, this PR builds on #18035 and #18147 to remove:

  • Commands::insert_or_spawn_batch
  • Entities::alloc_at_without_replacement
  • Entities::alloc_at
  • entity::AllocAtWithoutReplacement
  • World::insert_or_spawn_batch
  • World::insert_or_spawn_batch_with_caller

Testing

Just removing unused, deprecated code, so no new tests. Note that as of writing, #18035 is still under testing and review.

Future Work

Per this comment on #18054, there may be additional performance improvements possible to the entity allocator now that alloc_at no longer is supported. At a glance, I don't see anything obvious to improve, but it may be worth further investigation in the future.

Migration Guide

The following deprecated functions have been removed:

  • Commands::insert_or_spawn_batch
  • World::insert_or_spawn_batch
  • World::insert_or_spawn_batch_with_caller

These functions, when used incorrectly, can cause major performance problems and are generally viewed as anti-patterns and foot guns.

Instead of these functions consider doing one of the following:

Option A) Instead of despawing entities and re-spawning them at a particular id, insert the new Disabled component without despawning the entity, and use try_insert_batch or insert_batch and remove Disabled instead of re-spawning it.

Option B) Instead of giving special meaning to an entity id, simply use spawn_batch and ensure entity references are valid when despawning.

@alice-i-cecile alice-i-cecile added this to the 0.17 milestone Mar 4, 2025
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change S-Blocked This cannot move forward until something else changes C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Mar 4, 2025
@ElliottjPierce ElliottjPierce added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Blocked This cannot move forward until something else changes labels Apr 18, 2025
@ElliottjPierce
Copy link
Contributor Author

removed blocked since #18147 is merged.

Copy link
Contributor

@Henauxg Henauxg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a comment from Cart in #18054 saying

If we plan on removing support for this, we should also look into some of the "invalid checks" in Entities. Iirc we added additional checking to support this scenario, and we might be able to simplify / optimize some things. Worth digging up the PRs that introduced those changes.

Did someone have a look, if not we could maybe just track this somewhere ?

@ElliottjPierce
Copy link
Contributor Author

Did someone have a look, if not we could maybe just track this somewhere ?

Yup! I've rewritten most of the Entities allocator 9 times now lol. I'm picturing building from #18670 (which this is blocking). If we don't do v9, I'll take another look at what we end up with.

Also marking as ready for final since it has two approvals. (I think that's how that's supposed to work.)

@ElliottjPierce ElliottjPierce added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 25, 2025
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-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Performance of Entities::alloc_at
5 participants