bUseSoftGC
bUseSoftGC
#Overview
name: bUseSoftGC
The value of this variable can be defined or overridden in .ini config files. 1
.ini config file referencing this setting variable.
It is referenced in 10
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of bUseSoftGC is to control the use of a “soft” garbage collection mechanism during the cooking process in Unreal Engine 5. This setting is specifically related to memory management and optimization during content cooking.
The Unreal Engine subsystem that relies on this setting variable is the Cook On The Fly Server, which is part of the UnrealEd module. This can be seen from the file locations and class names in the callsites, such as UCookOnTheFlyServer and FCookDirector.
The value of this variable is set in the GEditorIni configuration file, under the [CookSettings] section. It is loaded in the UE::Cook::FInitializeConfigSettings::LoadLocal function.
Other variables that interact with bUseSoftGC include SoftGCStartNumerator and SoftGCDenominator, which are used to configure the soft GC behavior when bUseSoftGC is true.
Developers must be aware that this variable affects memory management during the cooking process. When enabled, it allows for a more gradual and controlled approach to garbage collection, which can be beneficial for performance in certain scenarios.
Best practices when using this variable include:
- Carefully consider whether to enable it based on your project’s specific needs and cooking performance.
- If enabled, tune the SoftGCStartNumerator and SoftGCDenominator values to achieve the desired balance between memory usage and garbage collection frequency.
- Monitor cooking performance and memory usage with and without this setting to determine its effectiveness for your project.
- Be aware that this setting is only applicable when cooking by the book and not when cooking in the editor.
#Setting Variables
#References In INI files
Location: <Workspace>/Engine/Config/BaseEditor.ini:375, section: [CookSettings]
- INI Section:
CookSettings
- Raw value:
true
- Is Array:
False
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Classes/CookOnTheSide/CookOnTheFlyServer.h:344
Scope (from outer to inner):
file
class class UCookOnTheFlyServer : public UObject, public FTickableEditorObject, public FExec, public UE::Cook::ICookInfo
Source code excerpt:
int32 SoftGCStartNumerator = 5;
int32 SoftGCDenominator = 10;
bool bUseSoftGC = false;
bool bWarnedExceededMaxMemoryWithinGCCooldown = false;
bool bGarbageCollectTypeSoft = false;
/**
* The maximum number of packages that should be preloaded at once. Once this is full, packages in LoadPrepare will
* remain unpreloaded in LoadPrepare until the existing preloaded packages exit {LoadPrepare,LoadReady} state.
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/CookOnTheFlyServer.cpp:5047
Scope (from outer to inner):
file
function bool UCookOnTheFlyServer::PumpHasExceededMaxMemory
Source code excerpt:
double CurrentTime = 0.;
bool bIsSoftGC = false;
if (!bTriggerGC && bUseSoftGC && IsDirectorCookByTheBook() && !IsCookingInEditor())
{
if (SoftGCNextAvailablePhysicalTarget == -1) // Uninitialized
{
int32 StartNumerator = FMath::Max(SoftGCStartNumerator, 1);
int32 Denominator = FMath::Max(SoftGCDenominator, 1);
// e.g. Start the target at 5/10, and decrease it by 1/10 each time the target is reached
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/CookOnTheFlyServer.cpp:6901
Scope (from outer to inner):
file
namespace UE::Cook
function void FInitializeConfigSettings::LoadLocal
Source code excerpt:
MemoryMinFreeVirtual = 0;
MemoryMinFreePhysical = 0;
bUseSoftGC = false;
SoftGCStartNumerator = 5;
SoftGCDenominator = 10;
ReadMemorySetting(TEXT("MemoryMaxUsedVirtual"), MemoryMaxUsedVirtual);
ReadMemorySetting(TEXT("MemoryMaxUsedPhysical"), MemoryMaxUsedPhysical);
ReadMemorySetting(TEXT("MemoryMinFreeVirtual"), MemoryMinFreeVirtual);
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/CookOnTheFlyServer.cpp:6916
Scope (from outer to inner):
file
namespace UE::Cook
function void FInitializeConfigSettings::LoadLocal
Source code excerpt:
*ConfigText);
}
GConfig->GetBool(TEXT("CookSettings"), TEXT("bUseSoftGC"), bUseSoftGC, GEditorIni);
GConfig->GetInt(TEXT("CookSettings"), TEXT("SoftGCStartNumerator"), SoftGCStartNumerator, GEditorIni);
GConfig->GetInt(TEXT("CookSettings"), TEXT("SoftGCDenominator"), SoftGCDenominator, GEditorIni);
MemoryExpectedFreedToSpreadRatio = 0.10f;
GConfig->GetFloat(TEXT("CookSettings"), TEXT("MemoryExpectedFreedToSpreadRatio"),
MemoryExpectedFreedToSpreadRatio, GEditorIni);
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/CookOnTheFlyServer.cpp:6942
Scope (from outer to inner):
file
namespace UE::Cook
function void FInitializeConfigSettings::LoadLocal
Source code excerpt:
MemoryMaxUsedVirtual / 1024 / 1024, MemoryMaxUsedPhysical / 1024 / 1024, MemoryMinFreeVirtual / 1024 / 1024, MemoryMinFreePhysical / 1024 / 1024,
*LexToString(MemoryTriggerGCAtPressureLevel),
bUseSoftGC ? TEXT("true") : TEXT("false"),
bUseSoftGC ? *FString::Printf(TEXT(" (%d/%d)"), SoftGCStartNumerator, SoftGCDenominator) : TEXT(""));
const FConfigSection* CacheSettings = GConfig->GetSection(TEXT("CookPlatformDataCacheSettings"), false, GEditorIni);
if (CacheSettings)
{
for (const auto& CacheSetting : *CacheSettings)
{
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Cooker/CookDirector.cpp:1080
Scope (from outer to inner):
file
namespace UE::Cook
function void FCookDirector::ActivateMachineResourceReduction
Source code excerpt:
COTFS.MemoryMinFreeVirtual / 1024 / 1024, COTFS.MemoryMinFreePhysical / 1024 / 1024,
*LexToString(COTFS.MemoryTriggerGCAtPressureLevel),
COTFS.bUseSoftGC ? TEXT("true") : TEXT("false"),
COTFS.bUseSoftGC ? *FString::Printf(TEXT(" (%d/%d)"), COTFS.SoftGCStartNumerator, COTFS.SoftGCDenominator) : TEXT("")
);
// Set CoreLimit for updating workerthreads in this process and passing to the commandline for workers
int32 NumProcesses = RequestedCookWorkerCount + 1;
int32 NumberOfCores = FPlatformMisc::NumberOfCores();
int32 HyperThreadCount = FPlatformMisc::NumberOfCoresIncludingHyperthreads();
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Cooker/CookTypes.cpp:626
Scope (from outer to inner):
file
function FCbWriter& operator<<
Source code excerpt:
Writer << "MemoryMinFreePhysical" << Value.MemoryMinFreePhysical;
Writer << "MemoryTriggerGCAtPressureLevel" << static_cast<uint8>(Value.MemoryTriggerGCAtPressureLevel);
Writer << "bUseSoftGC" << Value.bUseSoftGC;
Writer << "SoftGCStartNumerator" << Value.SoftGCStartNumerator;
Writer << "SoftGCDenominator" << Value.SoftGCDenominator;
Writer << "MinFreeUObjectIndicesBeforeGC" << Value.MinFreeUObjectIndicesBeforeGC;
Writer << "MaxNumPackagesBeforePartialGC" << Value.MaxNumPackagesBeforePartialGC;
Writer << "ConfigSettingDenyList" << Value.ConfigSettingDenyList;
Writer << "MaxAsyncCacheForType" << Value.MaxAsyncCacheForType;
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Cooker/CookTypes.cpp:661
Scope (from outer to inner):
file
function bool LoadFromCompactBinary
Source code excerpt:
bOk = false;
}
bOk = LoadFromCompactBinary(Field["bUseSoftGC"], OutValue.bUseSoftGC) & bOk;
bOk = LoadFromCompactBinary(Field["SoftGCStartNumerator"], OutValue.SoftGCStartNumerator) & bOk;
bOk = LoadFromCompactBinary(Field["SoftGCDenominator"], OutValue.SoftGCDenominator) & bOk;
bOk = LoadFromCompactBinary(Field["MinFreeUObjectIndicesBeforeGC"], OutValue.MinFreeUObjectIndicesBeforeGC) & bOk;
bOk = LoadFromCompactBinary(Field["MaxNumPackagesBeforePartialGC"], OutValue.MaxNumPackagesBeforePartialGC) & bOk;
bOk = LoadFromCompactBinary(Field["ConfigSettingDenyList"], OutValue.ConfigSettingDenyList) & bOk;
bOk = LoadFromCompactBinary(Field["MaxAsyncCacheForType"], OutValue.MaxAsyncCacheForType) & bOk;
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Cooker/CookTypes.cpp:689
Scope (from outer to inner):
file
namespace UE::Cook
function void FInitializeConfigSettings::MoveOrCopy
Source code excerpt:
Target.MemoryMinFreePhysical = Source.MemoryMinFreePhysical;
Target.MemoryTriggerGCAtPressureLevel = Source.MemoryTriggerGCAtPressureLevel;
Target.bUseSoftGC = Source.bUseSoftGC;
Target.SoftGCStartNumerator = Source.SoftGCStartNumerator;
Target.SoftGCDenominator = Source.SoftGCDenominator;
Target.MinFreeUObjectIndicesBeforeGC = Source.MinFreeUObjectIndicesBeforeGC;
Target.MaxNumPackagesBeforePartialGC = Source.MaxNumPackagesBeforePartialGC;
Target.ConfigSettingDenyList = MoveTempIfPossible(Source.ConfigSettingDenyList);
Target.MaxAsyncCacheForType = MoveTempIfPossible(Source.MaxAsyncCacheForType);
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Cooker/CookTypes.h:327
Scope (from outer to inner):
file
namespace UE::Cook
Source code excerpt:
TArray<FString> ConfigSettingDenyList;
TMap<FName, int32> MaxAsyncCacheForType; // max number of objects of a specific type which are allowed to async cache at once
bool bUseSoftGC = false;
friend FCbWriter& ::operator<<(FCbWriter& Writer, const UE::Cook::FInitializeConfigSettings& Value);
friend bool ::LoadFromCompactBinary(FCbFieldView Field, UE::Cook::FInitializeConfigSettings& Value);
};
struct FBeginCookConfigSettings