pub struct BatchingStrategy {
pub batch_size_limits: Range<usize>,
pub batches_per_thread: usize,
}
Expand description
Dictates how a parallel operation chunks up large quantities during iteration.
A parallel query will chunk up large tables and archetypes into chunks of at most a certain batch size. Similarly, a parallel event reader will chunk up the remaining events.
By default, this batch size is automatically determined by dividing the size of the largest matched archetype by the number of threads (rounded up). This attempts to minimize the overhead of scheduling tasks onto multiple threads, but assumes each entity has roughly the same amount of work to be done, which may not hold true in every workload.
See Query::par_iter
, EventReader::par_read
for more information.
Fields§
§batch_size_limits: Range<usize>
The upper and lower limits for a batch of entities.
Setting the bounds to the same value will result in a fixed batch size.
Defaults to [1, usize::MAX]
.
batches_per_thread: usize
The number of batches per thread in the ComputeTaskPool
.
Increasing this value will decrease the batch size, which may
increase the scheduling overhead for the iteration.
Defaults to 1.
Implementations§
source§impl BatchingStrategy
impl BatchingStrategy
sourcepub const fn new() -> BatchingStrategy
pub const fn new() -> BatchingStrategy
Creates a new unconstrained default batching strategy.
sourcepub const fn fixed(batch_size: usize) -> BatchingStrategy
pub const fn fixed(batch_size: usize) -> BatchingStrategy
Declares a batching strategy with a fixed batch size.
sourcepub const fn min_batch_size(self, batch_size: usize) -> BatchingStrategy
pub const fn min_batch_size(self, batch_size: usize) -> BatchingStrategy
Configures the minimum allowed batch size of this instance.
sourcepub const fn max_batch_size(self, batch_size: usize) -> BatchingStrategy
pub const fn max_batch_size(self, batch_size: usize) -> BatchingStrategy
Configures the maximum allowed batch size of this instance.
sourcepub fn batches_per_thread(self, batches_per_thread: usize) -> BatchingStrategy
pub fn batches_per_thread(self, batches_per_thread: usize) -> BatchingStrategy
Configures the number of batches to assign to each thread for this instance.
sourcepub fn calc_batch_size(
&self,
max_items: impl FnOnce() -> usize,
thread_count: usize,
) -> usize
pub fn calc_batch_size( &self, max_items: impl FnOnce() -> usize, thread_count: usize, ) -> usize
Calculate the batch size according to the given thread count and max item count. The count is provided as a closure so that it can be calculated only if needed.
§Panics
Panics if thread_count
is 0.
Trait Implementations§
source§impl Clone for BatchingStrategy
impl Clone for BatchingStrategy
source§fn clone(&self) -> BatchingStrategy
fn clone(&self) -> BatchingStrategy
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for BatchingStrategy
impl Debug for BatchingStrategy
source§impl Default for BatchingStrategy
impl Default for BatchingStrategy
source§fn default() -> BatchingStrategy
fn default() -> BatchingStrategy
Auto Trait Implementations§
impl Freeze for BatchingStrategy
impl RefUnwindSafe for BatchingStrategy
impl Send for BatchingStrategy
impl Sync for BatchingStrategy
impl Unpin for BatchingStrategy
impl UnwindSafe for BatchingStrategy
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self
using default()
.
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more