Class ParallelSystemBatcher
- Namespace
- KeenEyes
- Assembly
- KeenEyes.Core.dll
Analyzes system dependencies and groups systems into parallel execution batches.
public sealed class ParallelSystemBatcher
- Inheritance
-
ParallelSystemBatcher
- Inherited Members
Examples
var batcher = new ParallelSystemBatcher(dependencyTracker);
var batches = batcher.CreateBatches(sortedSystems);
foreach (var batch in batches)
{
// Execute all systems in this batch in parallel
Parallel.ForEach(batch, system => system.Update(deltaTime));
// Wait for batch completion before next batch
}
Remarks
The batcher respects both explicit ordering constraints (RunBefore/RunAfter) and component dependencies (read/write conflicts). Systems within a batch can safely execute in parallel, while batches execute sequentially.
The algorithm works in two phases: 1. Topologically sort systems respecting explicit ordering constraints 2. Greedily batch compatible systems that have no component conflicts
Constructors
ParallelSystemBatcher(SystemDependencyTracker)
Analyzes system dependencies and groups systems into parallel execution batches.
public ParallelSystemBatcher(SystemDependencyTracker dependencyTracker)
Parameters
dependencyTrackerSystemDependencyTrackerThe tracker containing component dependencies for systems.
Examples
var batcher = new ParallelSystemBatcher(dependencyTracker);
var batches = batcher.CreateBatches(sortedSystems);
foreach (var batch in batches)
{
// Execute all systems in this batch in parallel
Parallel.ForEach(batch, system => system.Update(deltaTime));
// Wait for batch completion before next batch
}
Remarks
The batcher respects both explicit ordering constraints (RunBefore/RunAfter) and component dependencies (read/write conflicts). Systems within a batch can safely execute in parallel, while batches execute sequentially.
The algorithm works in two phases: 1. Topologically sort systems respecting explicit ordering constraints 2. Greedily batch compatible systems that have no component conflicts
Methods
Analyze(IEnumerable<ISystem>)
Analyzes systems and returns detailed conflict information.
public BatchAnalysis Analyze(IEnumerable<ISystem> systems)
Parameters
systemsIEnumerable<ISystem>The systems to analyze.
Returns
- BatchAnalysis
Analysis result with conflict details.
CreateBatches(IEnumerable<ISystem>)
Groups systems into parallel execution batches based on their dependencies.
public IReadOnlyList<SystemBatch> CreateBatches(IEnumerable<ISystem> sortedSystems)
Parameters
sortedSystemsIEnumerable<ISystem>Systems already sorted by topological order (respecting RunBefore/RunAfter).
Returns
- IReadOnlyList<SystemBatch>
A list of batches, where each batch contains systems that can run in parallel.
Remarks
The input systems must already be topologically sorted to respect explicit ordering constraints. This method only considers component dependencies for parallel grouping.
Systems are greedily added to the current batch if they don't conflict with any system already in that batch. A new batch is started when a conflict is detected.
CreateTypeBatches(IEnumerable<Type>)
Groups system types into parallel execution batches based on their dependencies.
public IReadOnlyList<TypeBatch> CreateTypeBatches(IEnumerable<Type> sortedSystemTypes)
Parameters
sortedSystemTypesIEnumerable<Type>System types already sorted by topological order.
Returns
- IReadOnlyList<TypeBatch>
A list of batches, where each batch contains system types that can run in parallel.