ShrinkUObjectHashTables
ShrinkUObjectHashTables
#Overview
name: ShrinkUObjectHashTables
This variable is created as a Console Variable (cvar).
- type:
Cmd
- help:
Shrinks all of the UObject hash tables.
It is referenced in 5
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of ShrinkUObjectHashTables is to reduce the memory footprint of the UObject hash tables in Unreal Engine’s object management system. This function is part of the core object handling subsystem within the engine.
Based on the callsites, the ShrinkUObjectHashTables function is primarily used in the CoreUObject module, specifically within the UObject system. It’s referenced in files related to object hashing (UObjectHash.cpp) and garbage collection (GarbageCollection.cpp).
The value of this variable is not set directly, as it’s actually a function. It’s called in various contexts:
- As part of the post-garbage collection process when performing a full purge.
- Through a console command “ShrinkUObjectHashTables” for manual invocation.
There don’t appear to be other variables directly interacting with this function, but it does interact with the FUObjectHashTables class, specifically calling the ShrinkMaps() method on the singleton instance.
Developers should be aware that:
- This function is part of the low-level object management system and should be used cautiously.
- It’s automatically called during full garbage collection purges.
- It can be manually triggered via a console command, which might be useful for debugging or optimization purposes.
Best practices when using this function include:
- Generally, allow the engine to manage this automatically through garbage collection.
- If manual invocation is necessary, ensure it’s done at appropriate times when performance or memory optimization is critical.
- Be aware that shrinking hash tables could potentially impact performance if done too frequently, as it might cause more hash collisions.
- Use it in conjunction with profiling tools to measure its impact on memory usage and performance.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Private/UObject/UObjectHash.cpp:1165
Scope: file
Source code excerpt:
static FAutoConsoleCommand ShrinkUObjectHashTablesCmd(
TEXT("ShrinkUObjectHashTables"),
TEXT("Shrinks all of the UObject hash tables."),
FConsoleCommandWithArgsDelegate::CreateStatic(&ShrinkUObjectHashTablesDel)
);
void GetObjectsWithOuter(const class UObjectBase* Outer, TArray<UObject *>& Results, bool bIncludeNestedObjects, EObjectFlags ExclusionFlags, EInternalObjectFlags ExclusionInternalFlags)
{
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Private/UObject/GarbageCollection.cpp:5582
Scope (from outer to inner):
file
namespace UE::GC
function void PostCollectGarbageImpl
Source code excerpt:
if (bPerformFullPurge)
{
ShrinkUObjectHashTables();
}
// Destroy all pending delete linkers
DeleteLoaders();
if (bPerformFullPurge)
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Private/UObject/UObjectHash.cpp:1135
Scope (from outer to inner):
file
function void ShrinkUObjectHashTables
Source code excerpt:
}
void ShrinkUObjectHashTables()
{
LLM_SCOPE_BYTAG(UObjectHash);
LLM_SCOPE_DYNAMIC_STAT_OBJECTPATH_FNAME(FName{NAME_Default}, ELLMTagSet::Assets);
LLM_SCOPE_DYNAMIC_STAT_OBJECTPATH_FNAME(FName{NAME_Default}, ELLMTagSet::AssetClasses);
UE_TRACE_METADATA_SCOPE_ASSET_FNAME(NAME_None, NAME_None, NAME_None);
TRACE_CPUPROFILER_EVENT_SCOPE(ShrinkUObjectHashTables);
FUObjectHashTables& ThreadHash = FUObjectHashTables::Get();
FHashTableLock HashLock(ThreadHash);
ThreadHash.ShrinkMaps();
}
uint64 GetRegisteredClassesVersionNumber()
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Private/UObject/UObjectHash.cpp:1161
Scope (from outer to inner):
file
function static void ShrinkUObjectHashTablesDel
Source code excerpt:
static void ShrinkUObjectHashTablesDel(const TArray<FString>& Args)
{
ShrinkUObjectHashTables();
}
static FAutoConsoleCommand ShrinkUObjectHashTablesCmd(
TEXT("ShrinkUObjectHashTables"),
TEXT("Shrinks all of the UObject hash tables."),
FConsoleCommandWithArgsDelegate::CreateStatic(&ShrinkUObjectHashTablesDel)
#Loc: <Workspace>/Engine/Source/Runtime/CoreUObject/Public/UObject/UObjectHash.h:264
Scope: file
Source code excerpt:
* Shrink the UObject hash tables
*/
COREUOBJECT_API void ShrinkUObjectHashTables();
/**
* Get a version number representing the current state of registered classes.
*
* Can be stored and then compared to invalidate external caching of classes hierarchy whenever it changes.
*/