Skip to content

Commit

Permalink
chore: profile more heavy methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ten3roberts committed Mar 16, 2024
1 parent bb23e6e commit 561b16b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/entity/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ impl EntityBuilder {
/// Clears the builder and allows it to be used again, reusing the builder
/// will reuse the inner storage, even for different components.
pub fn spawn(&mut self, world: &mut World) -> Entity {
profile_function!();
let id = world.spawn_with(&mut self.buffer);

self.children.drain(..).for_each(|child| {
Expand Down Expand Up @@ -177,6 +178,7 @@ impl EntityBuilder {
///
/// New components will overwrite existing components.
pub fn append_to(&mut self, world: &mut World, id: Entity) -> Result<Entity> {
profile_function!();
world.set_with(id, &mut self.buffer)?;

self.children.drain(..).for_each(|child| {
Expand Down
8 changes: 8 additions & 0 deletions src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,20 @@ impl World {

/// Create an iterator to spawn several entities
pub fn spawn_many(&mut self) -> impl Iterator<Item = Entity> + '_ {
profile_function!();
(0..).map(|_| self.spawn())
}

/// Spawn a new empty entity into the default namespace
pub fn spawn(&mut self) -> Entity {
profile_function!();
self.spawn_inner(self.archetypes.root, EntityKind::empty())
.0
}

/// Spawn a new empty entity and acquire an entity reference.
pub fn spawn_ref(&mut self) -> EntityRefMut {
profile_function!();
let (id, loc, _) = self.spawn_inner(self.archetypes.root, EntityKind::empty());
EntityRefMut {
world: self,
Expand All @@ -147,6 +150,7 @@ impl World {

/// Efficiently spawn many entities with the same components at once.
pub fn spawn_batch(&mut self, chunk: &mut BatchSpawn) -> Vec<Entity> {
profile_function!();
self.flush_reserved();

for component in chunk.components() {
Expand Down Expand Up @@ -357,6 +361,7 @@ impl World {
/// Despawn an entity.
/// Any relations to other entities will be removed.
pub fn despawn(&mut self, id: Entity) -> Result<()> {
profile_function!();
self.flush_reserved();
let EntityLocation {
arch_id: arch,
Expand Down Expand Up @@ -395,6 +400,7 @@ impl World {
where
F: for<'x> Fetch<'x>,
{
profile_function!();
self.flush_reserved();
let mut query = Query::new(entity_ids()).filter(filter);
let ids = query.borrow(self).iter().collect_vec();
Expand All @@ -411,6 +417,7 @@ impl World {
id: Entity,
relation: impl RelationExt<T>,
) -> Result<()> {
profile_function!();
self.despawn_children(id, relation)?;
self.despawn(id)?;

Expand All @@ -423,6 +430,7 @@ impl World {
id: Entity,
relation: impl RelationExt<T>,
) -> Result<()> {
profile_function!();
self.flush_reserved();
let mut stack = alloc::vec![id];

Expand Down

0 comments on commit 561b16b

Please sign in to comment.