p.Chaos.SmallBatchSize
p.Chaos.SmallBatchSize
#Overview
name: p.Chaos.SmallBatchSize
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Small batch size for chaos parallel loops
It is referenced in 5
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.Chaos.SmallBatchSize is to set the small batch size for Chaos parallel loops in Unreal Engine’s physics system. This setting variable is used to control the granularity of parallel processing in the Chaos physics engine.
The Unreal Engine subsystem that relies on this setting variable is the Chaos physics engine, which is part of the experimental Chaos module. This can be seen from the file paths and namespaces in the provided code snippets.
The value of this variable is set through a console variable (CVar) system, as evident from the FAutoConsoleVariableRef declaration. This allows the value to be changed at runtime or through configuration files.
The associated variable SmallBatchSize interacts directly with p.Chaos.SmallBatchSize. They share the same value, with SmallBatchSize being the actual variable used in the code, while p.Chaos.SmallBatchSize is the console variable name used to set its value.
Developers must be aware that this variable affects the performance of parallel physics computations. A smaller batch size can lead to more fine-grained parallelism but may increase overhead, while a larger batch size might reduce overhead but could lead to less efficient load balancing.
Best practices when using this variable include:
- Experimenting with different values to find the optimal balance between parallelism and overhead for your specific use case.
- Considering the target hardware when setting this value, as different CPUs may perform better with different batch sizes.
- Monitoring performance metrics when adjusting this value to ensure it’s improving rather than degrading performance.
Regarding the associated variable SmallBatchSize:
The purpose of SmallBatchSize is to store the actual value used in the Chaos physics engine for small batch operations in parallel loops. It’s defined as an external integer variable in the Chaos namespace.
This variable is used directly in the physics code, such as in the RegisterCollisionEvent function, where it’s used to set the batch size for a parallel operation.
The value of SmallBatchSize is set through the p.Chaos.SmallBatchSize console variable, allowing for runtime configuration.
Developers should be aware that changes to SmallBatchSize will directly affect the behavior of parallel physics computations in the Chaos engine. It’s important to consider the implications on performance and accuracy when modifying this value.
Best practices for SmallBatchSize include:
- Using it consistently across related parallel operations for predictable behavior.
- Considering its value in relation to other batch size variables like LargeBatchSize.
- Documenting any custom values used in production to aid in performance tuning and debugging.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Framework/Parallel.cpp:24
Scope (from outer to inner):
file
namespace Chaos
Source code excerpt:
FAutoConsoleVariableRef CVarMinRangeBatchSize(TEXT("p.Chaos.MinRangeBatchSize"), MinRangeBatchSize, TEXT("Set the min range batch size for parallel for"));
FAutoConsoleVariableRef CVarMaxRangeBatchWorkers(TEXT("p.Chaos.MaxNumWorkers"), MaxNumWorkers, TEXT("Set the max number of workers for physics"));
FAutoConsoleVariableRef CVarSmallBatchSize(TEXT("p.Chaos.SmallBatchSize"), SmallBatchSize, TEXT("Small batch size for chaos parallel loops"));
FAutoConsoleVariableRef CVarLargeBatchSize(TEXT("p.Chaos.LargeBatchSize"), LargeBatchSize, TEXT("Large batch size for chaos parallel loops"));
#endif
}
void Chaos::InnerPhysicsParallelFor(int32 Num, TFunctionRef<void(int32)> InCallable, bool bForceSingleThreaded)
{
#Associated Variable and Callsites
This variable is associated with another variable named SmallBatchSize
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Framework/Parallel.cpp:10
Scope (from outer to inner):
file
namespace Chaos
Source code excerpt:
CHAOS_API int32 MinRangeBatchSize = 0;
CHAOS_API int32 MaxNumWorkers = 100;
CHAOS_API int32 SmallBatchSize = 10;
CHAOS_API int32 LargeBatchSize = 100;
#if !UE_BUILD_SHIPPING
CHAOS_API bool bDisablePhysicsParallelFor = false;
CHAOS_API bool bDisableParticleParallelFor = false;
CHAOS_API bool bDisableCollisionParallelFor = false;
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Framework/Parallel.cpp:24
Scope (from outer to inner):
file
namespace Chaos
Source code excerpt:
FAutoConsoleVariableRef CVarMinRangeBatchSize(TEXT("p.Chaos.MinRangeBatchSize"), MinRangeBatchSize, TEXT("Set the min range batch size for parallel for"));
FAutoConsoleVariableRef CVarMaxRangeBatchWorkers(TEXT("p.Chaos.MaxNumWorkers"), MaxNumWorkers, TEXT("Set the max number of workers for physics"));
FAutoConsoleVariableRef CVarSmallBatchSize(TEXT("p.Chaos.SmallBatchSize"), SmallBatchSize, TEXT("Small batch size for chaos parallel loops"));
FAutoConsoleVariableRef CVarLargeBatchSize(TEXT("p.Chaos.LargeBatchSize"), LargeBatchSize, TEXT("Large batch size for chaos parallel loops"));
#endif
}
void Chaos::InnerPhysicsParallelFor(int32 Num, TFunctionRef<void(int32)> InCallable, bool bForceSingleThreaded)
{
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/EventDefaults.cpp:281
Scope (from outer to inner):
file
namespace Chaos
function void FEventDefaults::RegisterCollisionEvent
lambda-function
Source code excerpt:
}
}
}, Chaos::SmallBatchSize);
FCollisionDataArray& AllCollisionsDataArray = CollisionEventData.CollisionData.AllCollisionsArray;
TMap<IPhysicsProxyBase*, TArray<int32>>& AllCollisionsIndicesByPhysicsProxy = CollisionEventData.PhysicsProxyToCollisionIndices.PhysicsProxyToIndicesMap;
for (int32 IdxCollision = 0; IdxCollision < NumValidCollisions; ++IdxCollision)
{
if (DupAllCollisionsDataArray[IdxCollision].Proxy1 != nullptr && !DupAllCollisionsDataArray[IdxCollision].Proxy1->GetMarkedDeleted())
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Public/Chaos/Framework/Parallel.h:15
Scope (from outer to inner):
file
namespace Chaos
Source code excerpt:
CHAOS_API extern int32 MaxNumWorkers;
CHAOS_API extern int32 SmallBatchSize;
CHAOS_API extern int32 LargeBatchSize;
#if UE_BUILD_SHIPPING
const bool bDisablePhysicsParallelFor = false;
const bool bDisableParticleParallelFor = false;
const bool bDisableCollisionParallelFor = false;
#else