mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-15 06:42:25 +02:00
Warmup system to speed up startup.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using System.Threading.Tasks;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Resources;
|
||||
using SixLabors.ImageSharp;
|
||||
|
||||
namespace Robust.Client;
|
||||
|
||||
/// <summary>
|
||||
/// Logic for "warming up" things like slow static constructors concurrently.
|
||||
/// </summary>
|
||||
internal static class ClientWarmup
|
||||
{
|
||||
public static void RunWarmup()
|
||||
{
|
||||
Task.Run(WarmupCore);
|
||||
}
|
||||
|
||||
private static void WarmupCore()
|
||||
{
|
||||
// Get ImageSharp loaded.
|
||||
_ = Configuration.Default;
|
||||
|
||||
SharedWarmup.WarmupCore();
|
||||
|
||||
// Preload the JSON loading code.
|
||||
RsiLoading.Warmup();
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,8 @@ namespace Robust.Client
|
||||
|
||||
private static void ParsedMain(CommandLineArgs args, bool contentStart, IMainArgs? loaderArgs, GameControllerOptions options)
|
||||
{
|
||||
ClientWarmup.RunWarmup();
|
||||
|
||||
var deps = IoCManager.InitThread();
|
||||
var mode = args.Headless ? DisplayMode.Headless : DisplayMode.Clyde;
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@ namespace Robust.Server
|
||||
|
||||
private static void ParsedMain(CommandLineArgs args, bool contentStart, ServerOptions options)
|
||||
{
|
||||
ServerWarmup.RunWarmup();
|
||||
|
||||
Thread.CurrentThread.Name = "Main Thread";
|
||||
var deps = IoCManager.InitThread();
|
||||
ServerIoC.RegisterIoC(deps);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Threading.Tasks;
|
||||
using Robust.Shared;
|
||||
|
||||
namespace Robust.Server;
|
||||
|
||||
/// <summary>
|
||||
/// Logic for "warming up" things like slow static constructors concurrently.
|
||||
/// </summary>
|
||||
internal static class ServerWarmup
|
||||
{
|
||||
public static void RunWarmup()
|
||||
{
|
||||
Task.Run(WarmupCore);
|
||||
}
|
||||
|
||||
private static void WarmupCore()
|
||||
{
|
||||
SharedWarmup.WarmupCore();
|
||||
}
|
||||
}
|
||||
@@ -96,6 +96,12 @@ internal static class RsiLoading
|
||||
return new RsiMetadata(size, states);
|
||||
}
|
||||
|
||||
public static void Warmup()
|
||||
{
|
||||
// Just a random RSI I pulled from SS14.
|
||||
const string warmupJson = @"{""version"":1,""license"":""CC-BY-SA-3.0"",""copyright"":""Space Wizards Federation"",""size"":{""x"":32,""y"":32},""states"":[{""name"":""mono""}]}";
|
||||
JsonSerializer.Deserialize<RsiJsonMetadata>(warmupJson, SerializerOptions);
|
||||
}
|
||||
|
||||
internal sealed class RsiMetadata
|
||||
{
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Robust.Shared;
|
||||
|
||||
/// <summary>
|
||||
/// Logic for "warming up" things like slow static constructors concurrently.
|
||||
/// </summary>
|
||||
internal static class SharedWarmup
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.NoOptimization)]
|
||||
public static void WarmupCore()
|
||||
{
|
||||
// Color's cctor unironically takes ~12ms.
|
||||
RuntimeHelpers.RunClassConstructor(typeof(Color).TypeHandle);
|
||||
|
||||
// This ends up initializing prometheus-net which takes quite a while.
|
||||
RuntimeHelpers.RunClassConstructor(typeof(EntitySystemManager).TypeHandle);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user