tick.DoAsyncEndOfFrameTasks.Randomize
tick.DoAsyncEndOfFrameTasks.Randomize
#Overview
name: tick.DoAsyncEndOfFrameTasks.Randomize
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Used to add random sleeps to tick.DoAsyncEndOfFrameTasks to shake loose bugs on either thread. Also does random render thread flushes from the game thread.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of tick.DoAsyncEndOfFrameTasks.Randomize is to introduce random delays and render thread flushes during the end-of-frame tasks processing, primarily for debugging and testing purposes. It is designed to help identify potential race conditions and threading issues in the engine’s tick system.
This setting variable is primarily used in the engine’s core tick system, specifically in the async end-of-frame tasks processing. Based on the callsites, it appears to be part of the LaunchEngineLoop module, which is a crucial component of Unreal Engine’s runtime.
The value of this variable is set through a console variable (CVar) system. It is initialized with a default value of 0, meaning the randomization is disabled by default.
The associated variable CVarDoAsyncEndOfFrameTasksRandomize interacts directly with this setting. It is used to retrieve the current value of the setting and determine whether to apply the randomization.
Developers must be aware that enabling this variable (setting it to a value greater than 0) will introduce intentional, random delays in the engine’s tick process. This can affect performance and potentially change the behavior of time-sensitive operations. It should primarily be used for debugging and testing purposes, not in production builds.
Best practices when using this variable include:
- Only enable it when actively debugging threading or race condition issues.
- Be prepared for potential performance impacts when enabled.
- Use it in conjunction with other debugging tools to isolate and identify threading issues.
- Disable it in production builds to avoid unnecessary performance overhead.
Regarding the associated variable CVarDoAsyncEndOfFrameTasksRandomize:
The purpose of CVarDoAsyncEndOfFrameTasksRandomize is to provide programmatic access to the tick.DoAsyncEndOfFrameTasks.Randomize setting within the C++ code.
This variable is part of the engine’s console variable system and is used in the LaunchEngineLoop module. It allows the engine to check the current value of the setting at runtime.
The value of this variable is set automatically by the console variable system based on the tick.DoAsyncEndOfFrameTasks.Randomize setting.
It interacts directly with the tick.DoAsyncEndOfFrameTasks.Randomize setting, essentially serving as its in-code representation.
Developers should be aware that this variable provides a thread-safe way to access the setting’s value, as evidenced by the use of GetValueOnAnyThread() in the code.
Best practices for using this variable include:
- Use GetValueOnAnyThread() when accessing the value from multiple threads.
- Consider caching the value if it’s accessed frequently in performance-critical code.
- Be aware that changes to the setting via console commands will be reflected in this variable’s value.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Launch/Private/LaunchEngineLoop.cpp:313
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarDoAsyncEndOfFrameTasksRandomize(
TEXT("tick.DoAsyncEndOfFrameTasks.Randomize"),
0,
TEXT("Used to add random sleeps to tick.DoAsyncEndOfFrameTasks to shake loose bugs on either thread. Also does random render thread flushes from the game thread.")
);
static TAutoConsoleVariable<int32> CVarDoAsyncEndOfFrameTasksValidateReplicatedProperties(
TEXT("tick.DoAsyncEndOfFrameTasks.ValidateReplicatedProperties"),
#Associated Variable and Callsites
This variable is associated with another variable named CVarDoAsyncEndOfFrameTasksRandomize
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Launch/Private/LaunchEngineLoop.cpp:312
Scope: file
Source code excerpt:
);
static TAutoConsoleVariable<int32> CVarDoAsyncEndOfFrameTasksRandomize(
TEXT("tick.DoAsyncEndOfFrameTasks.Randomize"),
0,
TEXT("Used to add random sleeps to tick.DoAsyncEndOfFrameTasks to shake loose bugs on either thread. Also does random render thread flushes from the game thread.")
);
static TAutoConsoleVariable<int32> CVarDoAsyncEndOfFrameTasksValidateReplicatedProperties(
#Loc: <Workspace>/Engine/Source/Runtime/Launch/Private/LaunchEngineLoop.cpp:6000
Scope (from outer to inner):
file
lambda-function
Source code excerpt:
[CurrentDemoNetDriver, DeltaSeconds]()
{
if (CVarDoAsyncEndOfFrameTasksRandomize.GetValueOnAnyThread(true) > 0)
{
FPlatformProcess::Sleep(FMath::RandRange(0.0f, .003f)); // this shakes up the threading to find race conditions
}
if (CurrentDemoNetDriver != nullptr)
{