Improve component registration performance (#18180)
# Objective Make component registration faster. This is a tinny, almost petty PR, but it led to roughly 10% faster registration, according to my benchmarks in #17871. Up to y'all if we do this or not. It is completely unnecessary, but its such low hanging fruit that I wanted to put it out there. ## Solution Instead of cloning a `HashSet`, collect it into a `SmallVec`. Since this is empty for many components, this saves a lot of allocation and hashing work. Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
This commit is contained in:
parent
0cf1dc12e0
commit
21f003f13f
@ -34,6 +34,7 @@ use core::{
|
|||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
};
|
};
|
||||||
use disqualified::ShortName;
|
use disqualified::ShortName;
|
||||||
|
use smallvec::SmallVec;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
/// A data type that can be used to store data for an [entity].
|
/// A data type that can be used to store data for an [entity].
|
||||||
@ -2067,7 +2068,10 @@ impl Components {
|
|||||||
required_components.0.extend(required_components_tmp.0);
|
required_components.0.extend(required_components_tmp.0);
|
||||||
|
|
||||||
// Propagate the new required components up the chain to all components that require the requiree.
|
// Propagate the new required components up the chain to all components that require the requiree.
|
||||||
if let Some(required_by) = self.get_required_by(requiree).cloned() {
|
if let Some(required_by) = self
|
||||||
|
.get_required_by(requiree)
|
||||||
|
.map(|set| set.iter().copied().collect::<SmallVec<[ComponentId; 8]>>())
|
||||||
|
{
|
||||||
// `required` is now required by anything that `requiree` was required by.
|
// `required` is now required by anything that `requiree` was required by.
|
||||||
self.get_required_by_mut(required)
|
self.get_required_by_mut(required)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
Loading…
Reference in New Issue
Block a user