Mark large replays as requiring Server GC.

This should significantly improve loading performance of large replays.

System can be controlled by replay.server_gc_size_threshold, which defaults to 50 MiB.

This is the engine-side of https://github.com/space-wizards/SS14.Launcher/issues/177
This commit is contained in:
Pieter-Jan Briers
2024-09-09 08:23:12 +02:00
parent dbc4e80e61
commit 814e5bcf17
2 changed files with 22 additions and 1 deletions

View File

@@ -1636,6 +1636,16 @@ namespace Robust.Shared
public static readonly CVarDef<long> ReplayMaxUncompressedSize = CVarDef.Create("replay.max_uncompressed_size",
1024L * 1024, CVar.ARCHIVE);
/// <summary>
/// Size of the replay (in kilobytes) at which point the replay is considered "large",
/// and replay clients should enable server GC (if possible) to improve performance.
/// </summary>
/// <remarks>
/// Set to -1 to never make replays use server GC.
/// </remarks>
public static readonly CVarDef<long> ReplayServerGCSizeThreshold =
CVarDef.Create("replay.server_gc_size_threshold", 50L * 1024);
/// <summary>
/// Uncompressed size of individual files created by the replay (in kilobytes), where each file contains data
/// for one or more ticks. Actual files may be slightly larger, this is just a threshold for the file to get

View File

@@ -58,6 +58,7 @@ internal abstract partial class SharedReplayRecordingManager : IReplayRecordingM
// Config variables.
private long _maxCompressedSize;
private long _maxUncompressedSize;
private long _serverGCSizeThreshold;
private int _tickBatchSize;
private bool _enabled;
@@ -71,6 +72,7 @@ internal abstract partial class SharedReplayRecordingManager : IReplayRecordingM
NetConf.OnValueChanged(CVars.ReplayMaxCompressedSize, (v) => _maxCompressedSize = SaturatingMultiplyKb(v), true);
NetConf.OnValueChanged(CVars.ReplayMaxUncompressedSize, (v) => _maxUncompressedSize = SaturatingMultiplyKb(v), true);
NetConf.OnValueChanged(CVars.ReplayServerGCSizeThreshold, (v) => _serverGCSizeThreshold = SaturatingMultiplyKb(v), true);
NetConf.OnValueChanged(CVars.ReplayTickBatchSize, (v) => _tickBatchSize = Math.Min(v, MaxTickBatchSize) * 1024, true);
NetConf.OnValueChanged(CVars.NetPvsCompressLevel, OnCompressionChanged);
}
@@ -238,7 +240,6 @@ internal abstract partial class SharedReplayRecordingManager : IReplayRecordingM
try
{
WriteContentBundleInfo(_recState);
WriteInitialMetadata(name, _recState);
}
catch
@@ -391,6 +392,7 @@ internal abstract partial class SharedReplayRecordingManager : IReplayRecordingM
// this just overwrites the previous yml with additional data.
var document = new YamlDocument(yamlMetadata.ToYaml());
WriteYaml(recState, ReplayZipFolder / FileMetaFinal, document);
WriteContentBundleInfo(recState);
UpdateWriteTasks();
Reset();
@@ -412,6 +414,7 @@ internal abstract partial class SharedReplayRecordingManager : IReplayRecordingM
var document = new JsonObject
{
["server_gc"] = ShouldEnableServerGC(recState),
["engine_version"] = info.EngineVersion,
["base_build"] = new JsonObject
{
@@ -429,6 +432,14 @@ internal abstract partial class SharedReplayRecordingManager : IReplayRecordingM
WriteBytes(recState, new ResPath("rt_content_bundle.json"), bytes);
}
private bool ShouldEnableServerGC(RecordingState recState)
{
if (_serverGCSizeThreshold < 0)
return false;
return recState.CompressedSize >= _serverGCSizeThreshold;
}
/// <summary>
/// Get information describing the server build.
/// This will be embedded in replay content bundles to allow the launcher to directly load them.