Skip to content

Commit

Permalink
perf fix; cache GetEngineVersion result at serialization time
Browse files Browse the repository at this point in the history
  • Loading branch information
atenfyr committed Dec 17, 2024
1 parent e28d709 commit 177b647
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions UAssetAPI/UAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,7 @@ public override MemoryStream WriteData()
finally
{
isSerializationTime = false;
GetEngineVersion(); // update dirty state
}
return stre;
}
Expand Down
14 changes: 14 additions & 0 deletions UAssetAPI/UnrealPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -566,12 +566,26 @@ public static EngineVersion GetEngineVersion(ObjectVersion objectVersion, Object
return EngineVersion.UNKNOWN;
}

private EngineVersion _cachedEngineVersion = EngineVersion.UNKNOWN;
private bool _cachedEngineVersionDirty = true; // used only at serialization time to determine if we need to re-evaluate this

/// <summary>
/// Estimates the retail version of the Unreal Engine based on the object and custom versions.
/// </summary>
/// <returns>The estimated retail version of the Unreal Engine.</returns>
public EngineVersion GetEngineVersion()
{
if (isSerializationTime)
{
if (_cachedEngineVersionDirty)
{
_cachedEngineVersionDirty = false;
_cachedEngineVersion = UnrealPackage.GetEngineVersion(ObjectVersion, ObjectVersionUE5, CustomVersionContainer);
}
return _cachedEngineVersion;
}

_cachedEngineVersionDirty = true;
return UnrealPackage.GetEngineVersion(ObjectVersion, ObjectVersionUE5, CustomVersionContainer);
}

Expand Down

0 comments on commit 177b647

Please sign in to comment.