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

[Merged by Bors] - use bevy_utils::HashMap for better performance. TypeId is predefined … #7642

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion crates/bevy_ecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ async-channel = "1.4"
event-listener = "2.5"
thread_local = "1.1.4"
fixedbitset = "0.4.2"
fxhash = "0.2"
downcast-rs = "1.2"
serde = { version = "1", features = ["derive"] }

Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_ecs/src/archetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use crate::{
storage::{ImmutableSparseSet, SparseArray, SparseSet, SparseSetIndex, TableId, TableRow},
};
use std::{
collections::HashMap,
hash::Hash,
ops::{Index, IndexMut},
};
Expand Down Expand Up @@ -601,7 +600,7 @@ impl SparseSetIndex for ArchetypeComponentId {
pub struct Archetypes {
pub(crate) archetypes: Vec<Archetype>,
pub(crate) archetype_component_count: usize,
archetype_ids: HashMap<ArchetypeIdentity, ArchetypeId>,
archetype_ids: bevy_utils::HashMap<ArchetypeIdentity, ArchetypeId>,
}

impl Archetypes {
Expand Down
5 changes: 3 additions & 2 deletions crates/bevy_ecs/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ use crate::{
component::{Component, ComponentId, ComponentStorage, Components, StorageType, Tick},
entity::{Entities, Entity, EntityLocation},
storage::{SparseSetIndex, SparseSets, Storages, Table, TableRow},
TypeIdMap,
};
use bevy_ecs_macros::all_tuples;
use bevy_ptr::OwningPtr;
use std::{any::TypeId, collections::HashMap};
use std::any::TypeId;

/// The `Bundle` trait enables insertion and removal of [`Component`]s from an entity.
///
Expand Down Expand Up @@ -683,7 +684,7 @@ impl<'a, 'b> BundleSpawner<'a, 'b> {
#[derive(Default)]
pub struct Bundles {
bundle_infos: Vec<BundleInfo>,
bundle_ids: HashMap<TypeId, BundleId>,
bundle_ids: TypeIdMap<BundleId>,
}

impl Bundles {
Expand Down
5 changes: 3 additions & 2 deletions crates/bevy_ecs/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
storage::{SparseSetIndex, Storages},
system::{Local, Resource},
world::{FromWorld, World},
TypeIdMap,
};
pub use bevy_ecs_macros::Component;
use bevy_ptr::{OwningPtr, UnsafeCellDeref};
Expand Down Expand Up @@ -400,8 +401,8 @@ impl ComponentDescriptor {
#[derive(Debug, Default)]
pub struct Components {
components: Vec<ComponentInfo>,
indices: std::collections::HashMap<TypeId, usize, fxhash::FxBuildHasher>,
resource_indices: std::collections::HashMap<TypeId, usize, fxhash::FxBuildHasher>,
indices: TypeIdMap<usize>,
resource_indices: TypeIdMap<usize>,
}

impl Components {
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_ecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub mod storage;
pub mod system;
pub mod world;

use std::any::TypeId;

pub use bevy_ptr as ptr;

/// Most commonly used re-exported types.
Expand Down Expand Up @@ -52,6 +54,9 @@ pub mod prelude {

pub use bevy_ecs_macros::all_tuples;

/// A specialized hashmap type with Key of `TypeId`
type TypeIdMap<V> = bevy_utils::StableHashMap<TypeId, V>;

#[cfg(test)]
mod tests {
use crate as bevy_ecs;
Expand Down